React Core & Hooks (407 Qs)•Part 9: React Hooks Deep Dive (262 - 316)
Is dispatch from useReducer asynchronous and does it update state immediately?
mid LevelHooksAsync & Promises
The dispatch function returned by useReducer is not asynchronous — it is a synchronous function call. When you call dispatch(action), React synchronously invokes your reducer with the current state and the action, computes the new state, and schedules a re-render. However, the state variable does not update immediately within the same render cycle. The updated state is only available in the next render.
This behavior is similar to useState's setState — React batches state updates for performance optimization.