When do I use Context, useReducer or a custom hook?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn When do I use Context, useReducer or a custom hook?
Definition:
Context shares a value with descendants without passing it through every intermediate component. useReducer organizes state changes through actions and a reducer, while custom hooks extract reusable stateful logic. These tools address distribution, transition structure and reuse respectively; they are not interchangeable state stores.
Key points:
-
Context shares values across a component tree; changed values update consumers.
-
useReducer groups related state changes into explicit actions.
-
A custom hook reuses logic; separate calls do not automatically share state.
-
A new Context provider value can update consumers; separate unrelated contexts when broad updates become expensive.
Interview point:
- Two components calling the same custom hook get separate state unless the hook explicitly connects them to shared storage.
Adapted from 06_REACT_NEXTJS.md · “When do I use Context, useReducer or a custom hook?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.