The useContext hook allows you to share data across components without passing props manually at every level (also known as prop drilling).
useContext?Without context:
With context:
Data is stored in one place
Any component can access it directly
Context provides a way to pass data through the component tree without using props.
Typical use cases:
Theme (light/dark)
Authentication
Language settings
Global user data
useContext
Wrap components with a Provider.
useContext
Consume it:
Used when no Provider is found.
Context values update all consuming components.
❌ Using context for everything
❌ Forgetting to wrap Provider
❌ Storing large, frequently changing data
useContext✅ Good for:
Global app settings
Authentication data
Theme and localization
❌ Avoid for:
High-frequency updates
Deeply complex state logic
| Context | Redux |
|---|---|
| Built-in | External library |
| Simple global state | Complex state management |
| Small to medium apps | Large apps |
Keep context values small
Split contexts by responsibility
Memoize context values if needed
useContext avoids prop drilling
Works with createContext
Provider shares data
All consumers re-render on change
Take quizzes related to this topic and see where you stand!
Start Quiz Now