State: snapshots, updates and where state lives · mid
useReducer: explicit state transitions
Use useReducer when several values change together or the next state depends on the current one through clear rules; the reducer is a pure function you can unit-test, and dispatch is stable.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
const [state, dispatch] = useReducer(reducer, initialArg, init?); the reducer is(state, action) => newStateand must be pure (no fetch, no random ids, no mutation).- Good fits: forms with related fields, wizards, a fetch status machine (idle, loading, success, error), undo/redo, anything where "events" describe what happened.
dispatchhas a stable identity, so passing it down avoids creating new callbacks.- Reducers are easy to test without React: call them with a state and an action and check the result.
- Async work does not go inside the reducer; do it in an event handler or effect and dispatch actions before and after.
useReducer+ Context is a "mini Redux", but every consumer re-renders when the state object changes; there are no selectors.- It is not faster than
useState; it is a code-organisation choice.
The red pen
Common traps: mistake → fix
Mistake: "useReducer is faster"
Fix: same render cost; it is about clarity.
Mistake: "Put the API call in the reducer"
Fix: reducers must be pure; React may call them more than once.
Mistake: "Context + useReducer replaces Redux for any app"
Fix: no selectors, every consumer re-renders, no middleware or devtools.
Easy to hard
Questions interviewers ask, easy to hard
- When do you choose
useReduceroveruseState? - Refactor a form with six related
useStates. What actions would you define? - Is
dispatchstable? Why does that matter? - Where do async side effects go?
- When do you graduate from Context +
useReducerto Zustand or Redux Toolkit?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.