React state batching means React groups several state updates made in the same event into one re-render instead of re-rendering after each call. It makes components faster and keeps the UI from showing half-finished states. Since React 18, batching is automatic everywhere, including timeouts, promises and native event handlers.
This guide explains what gets batched, how the queue works, what changed from React 17, and the rare cases where you opt out. Examples target React 19 with function components.
Without batching, every setter call would trigger a render. With it, React waits until the event handler finishes, applies all queued updates in order and renders once.
Clicking the button logs render once, not twice. The user never sees a screen with the new name and the old age.
Every setter call adds an entry to the component's update queue. When React processes the queue during the next render, it starts from the previous state and applies each entry in order.
| Call | Queue entry | Result |
|---|---|---|
setCount(5) | replace with 5 | 5 |
setCount(c => c + 1) | apply function | 6 |
setCount(10) | replace with 10 | 10 |
A plain value replaces whatever came before, and an updater function transforms it. This is why setCount(count + 1) repeated three times yields one increment, while setCount(c => c + 1) repeated three times yields three.
React applies "replace with 1", "replace with 1", then "add 1 to the previous", which gives 2. Mixing styles makes this hard to read, so prefer updater functions when values depend on each other.
Before React 18, only updates inside React event handlers were batched. Updates in setTimeout, promises or native event listeners caused one render per setter call. React 18 introduced automatic batching, which applies to every source of updates when you use createRoot.
Apps still using the legacy ReactDOM.render keep the old behaviour, so migrate to createRoot to get batching everywhere.
React batches updates within one tick of one event. Two separate user events, such as two clicks, are processed separately. React also ensures a discrete event such as a click is fully rendered before the next one is handled, so a second click always sees the updated state of the first.
Rendering can also be interrupted. With transitions and useDeferredValue, React may render lower-priority updates later, and it can render a component more than once before committing. Never rely on render counts for logic.
Batching also covers code after an await, but each synchronous block between awaits is its own batch.
The first call renders saving (React flushes the pending update when the handler's synchronous part ends). After the await, the last two calls are batched into one render. Do not assume everything in an async function is one batch.
In rare cases you need the DOM updated immediately after one specific update, for example to scroll to a newly added element. flushSync from react-dom forces a synchronous render for the updates inside its callback.
flushSync is slower, can cause layout thrashing and should not be used for ordinary state changes.
Effects run after a render commits, and they see the final batched state. If you set three state variables in a handler and an effect depends on all of them, the effect runs once, not three times.
This is another reason to avoid chains of effects that set state, because each link adds a render.
No. Debouncing delays work over time. Batching merges updates from the same event into one render without any delay the user can notice.
No. It happens automatically in React 18 and later. You only need to write correct setter calls.
Yes. this.setState calls are batched the same way when the app uses createRoot.
Log inside the component body or use the React DevTools Profiler. A single commit per event means batching worked.
Batching queues state updates and renders once per event. React 18 extended it to timeouts, promises and native handlers. Setter calls are applied in order, plain values replace and updater functions transform, and flushSync is the escape hatch you rarely need.