Use useReducer instead of useState when one piece of state has several related fields, when the next state depends on the previous one in non-trivial ways, or when many different events update the same state. Use useState for independent, simple values such as a toggle, a text input or a counter. This guide compares usereducer vs usestate with the same example written both ways, so you can see where the reducer starts to pay off.
Neither hook is better in general. They both store state in a component, and useState is actually built on the same mechanism as useReducer. The difference is how you organise the update logic.
Imagine a signup form with a name, an email, a submitting flag and an error message. With useState you often end up with several separate variables, and event handlers that must update them together:
This is fine for a small form. The risk grows as more handlers touch status and error: each handler must remember to reset the right combination, and it is easy to land in a state such as status: "success" with a stale error.
With useReducer, the allowed transitions live in one function. Every handler only describes the event:
Starting a submit always clears the error, because that rule exists in exactly one place.
| Aspect | useState | useReducer |
|---|---|---|
| Code size for simple state | Less | More boilerplate |
| Many related fields | Several hooks to keep in sync | One state object, one update path |
| Update logic | Spread across event handlers | Centralised in the reducer |
| Next state depends on previous | Possible with updater functions | Natural |
| Testing | Test through the component | Test the reducer as a plain function |
| Debugging | Log in each handler | Log each action in one place |
Pick useState when:
setOpen(true).Splitting unrelated values into several useState calls is a good habit. Merging everything into one big object just to use useReducer makes the code harder to read.
Pick useReducer when:
idle, loading and error, where only some transitions are valid.dispatch to deep children. Its identity is stable, so passing it through context does not cause extra renders by itself.You can also start with useState and move to useReducer later. The migration is mechanical, so there is no need to choose perfectly on day one.
Not in any meaningful way. Both trigger a re-render when the state changes. Choose between them for clarity and maintainability, not performance.
Yes. A common pattern is useReducer for a complex form and useState for an unrelated flag such as whether a panel is open.
Often not. useReducer combined with context covers many apps. Redux adds middleware, devtools and a global store, which matter mainly in larger applications.
The reducer itself must stay synchronous and pure. Run the async work in an event handler or effect and dispatch actions for the start, success and failure.
useState suits simple, independent values. useReducer suits related fields, many update paths and rules you want to test in isolation. Both are valid, they can live in the same component, and moving from one to the other is straightforward when the state grows.