A sign you may benefit from useReducer: You're making multiple setState...


A sign you may benefit from useReducer: You're making multiple setState calls in a row.

With useReducer, multiple pieces of state can be updated via a single dispatch.

Another useReducer benefit: It "protects" the state.

So you can validate data, set related state, or derive settings in one spot. 👍

Alternatively, you can unify separate pieces of related state into a single useState call.

But, this doesn’t provide the same power, safety, and testability as useReducer.

View original on X