Q21: When should you use useReducer instead of useState?
useReducer is preferred over useState for complex state logic involving multiple sub-values, when next state depends on previous state, or when managing state transitions using Redux-style action dispatches.
Key Takeaways
useReducermanages complex or grouped state state machines via(state, action) => newState.- Improves maintainability by decoupling state updates from event handlers.
Knowledge Check
What is the signature of the reducer function passed to useReducer?