What is `useReducer`? Why do you use useReducer?
Assesses fundamental understanding of React conventions, runtime behavior, and memory/performance considerations.
Hiring managers look for precision, avoidance of ambiguous jargon, and ability to explain trade-offs under real production conditions.
The useReducer hook is a React hook used to manage complex state logic inside functional components. It is conceptually similar to Redux. i.e, Instead of directly updating state like with useState, you dispatch an action to a reducer function, and the reducer returns the new state.
The useReducer hook takes three arguments:
const [state, dispatch] = useReducer(reducer, initialState, initFunction);
reducer: A function(state, action) => newStatethat handles how state should change based on the action.initialState: The starting state.dispatch: A function you call to trigger an update by passing an action.
The useReducer hook is used when:
- The state is complex, such as nested structures or multiple related values.
- State updates depend on the previous state and logic.
- You want to separate state update logic from UI code to make it cleaner and testable.
- You’re managing features like:
- Forms
- Wizards / Multi-step flows
- Undo/Redo functionality
- Shopping cart logic
- Toggle & conditional UI logic
Candidate Response Strategy & Interview Tips
- Start with a concise one-sentence summary: Deliver a direct, confident answer first before expanding into nuances.
- Demonstrate real-world trade-offs: Discuss where this approach excels and when you would avoid it in production systems.
- Discuss complexity & edge cases: Proactively explain time/space complexity or boundary conditions (null values, scale limits).
- Prepare for interviewer follow-ups: Technical hiring panels frequently probe deeper into concurrency, backward compatibility, or alternative libraries.