React · Middle · Question 9 of 75
When is useReducer preferable to useState?
- 1When the state is a single boolean toggle
- ✓Correct answer: When there are many related fields and complex transitions
- 3Only when you need access to global state
Explanation
useReducer gathers update logic into one pure function (state, action) => newState: it's easy to read and test, and handlers only describe what happened (dispatch({ type: 'added' })). dispatch is stable and convenient to pass down. It doesn't make the state global.