What is useReducer?
useReducer is useful when a component has complex state or many related state transitions.
Instead of updating state in many different places, you define actions and one reducer function that explains how each action changes the state.
Reducer Pattern
- State: Current application data.
- Action: Describes what happened.
- Reducer: Calculates the next state.
- Dispatch: Sends an action to the reducer.
When Should You Use It?
It is useful for shopping carts, complex forms, multi-step workflows, and state containing many related transitions.