Q8: What is the React Context API and when should you use it?
The Context API provides a way to pass data through the component tree without manually passing props at every level (prop drilling). It is ideal for global state like user authentication, theme settings, or language preferences.
Key Takeaways
- Context solves prop drilling by exposing data globally to wrapped component subtrees.
- Best used for broadcasted low-frequency updates like user sessions, themes, or locale.
Knowledge Check
Which hook is used to consume values from a React Context in functional components?