What is useReducer and when is it better than useState?
Quick answer
useReducer manages state via a pure reducer(state, action) and dispatched actions. Prefer it for complex state with many transitions or interdependent values.
In detail
useReducer centralises update logic in one pure function, making transitions explicit and testable, and the dispatch function is stable. Reach for it when state has multiple sub-values that change together, when the next state depends intricately on the previous, or when you want to move logic out of the component. For simple independent values, useState is simpler.
1function reducer(s, a) {
2 switch (a.type) {
3 case 'inc': return { count: s.count + 1 };
4 case 'reset': return { count: 0 };
5 default: return s;
6 }
7}
8const [state, dispatch] = useReducer(reducer, { count: 0 });
9dispatch({ type: 'inc' });Why interviewers ask this: Tests judgement on state-management tools within React.
This is 1 of 118+ questions in the React Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the React Interview Kit → ₹399