React · Frontend system thinking
When should you use useReducer instead of useState?
Short answer
Use useState for simple independent values. Use useReducer when state has several related transitions, the next state depends on the previous one, or the update logic should be centralized and tested.
Both manage local state. The difference is how updates are expressed. A reducer moves state transition logic into a pure function that receives the current state and an action.
function reducer(state, action) {
switch (action.type) {
case "increment":
return { ...state, count: state.count + 1 };
case "reset":
return { count: 0 };
default:
return state;
}
}
const [state, dispatch] = useReducer(reducer, { count: 0 });How to choose
useStatefor a boolean, a single input, or a small independent valueuseReducerfor a form, a wizard, or a state machine with named actionsuseReducerwhen many handlers update the same state in different waysuseReducerwhen you want the transition logic to be unit-testable without React
A reducer must be pure: no mutation of the previous state, no side effects and no random values. Return a new state object when something changes.
useReducer is local state management, not a replacement for a global store. It becomes global only if you pass the state and dispatch through context or another store.Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1When is `useReducer` better than `useState`?
- 2Why must a reducer be pure?
- 3How do you initialize a reducer lazily?
- 4Is `useReducer` a replacement for Redux?
Say it in the interview
useState is best for simple independent values. useReducer is better when state has several related transitions or when the next state depends on the previous one, because it centralizes the logic in a pure reducer function. The reducer is easy to test without React. useReducer is still local state; it only becomes global if I pass it through context or a store.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.