What is State Batching in React? A Beginner-Friendly Guide
Learn how React batches state updates into fewer renders, why updater functions matter, and how automatic batching works in React 18 and later.

What is State Batching in React?
Imagine a click handler updates a few related pieces of state. React could render the component after every setter call, but that would often do unnecessary work. Instead, React usually groups updates that happen during the same event and renders after the handler finishes. This is called batching.
Batching makes updates more efficient and helps your UI move from one consistent state to another. It also connects to the state snapshot idea: setters do not change the state variable in the current render. When an update depends on another queued update, use an updater function.
A simple example
This component tracks a score and whether a message is visible:
import { useState } from "react";
function Scoreboard() {
const [score, setScore] = useState(0);
const [showMessage, setShowMessage] = useState(false);
function handleClick() {
setScore(score + 1);
setShowMessage(true);
}
return (
<section>
<p>Score: {score}</p>
{showMessage && <p>Point added!</p>}
<button onClick={handleClick}>Add a point</button>
</section>
);
}
Both setters run in the same click handler. React queues the updates and can render the component once with both new values, instead of rendering once for the score and again for the message.
Why batch updates?
Without batching, several updates from one interaction could cause several render passes. Batching helps React avoid that extra work and lets the UI reflect the related changes together. It does not mean React combines your state variables into one value: score and showMessage remain separate pieces of state. React groups the work of processing their updates and rendering.
Also, a render is not the same as a DOM change. React may render a component and determine that only some parts of the displayed UI need updating.
Batching is not the same as calculating the next value
Consider this click handler:
function handleAddThree() {
setScore(score + 1);
setScore(score + 1);
setScore(score + 1);
}
All three expressions use score from the same render snapshot. If the current score is 0, each asks React to replace it with 1. Batching does not turn those three calculations into 0 + 1, then 1 + 1, then 2 + 1.
To apply multiple increments in order, use updater functions:
function handleAddThree() {
setScore((previousScore) => previousScore + 1);
setScore((previousScore) => previousScore + 1);
setScore((previousScore) => previousScore + 1);
}
React puts these functions in the update queue and applies each to the result of the previous one. Starting at 0, the final score is 3. Batching controls when React processes and renders the updates; updater functions describe how to calculate each next value.
Use the functional form whenever the next state depends on the previous state, even when you are only making one update:
setScore((previousScore) => previousScore + pointsEarned);
For a value that does not depend on the previous state, a direct update is perfectly fine:
setShowMessage(true);
What about updates after a timer or Promise?
Batching behavior depends on the React version and how the app is mounted. In React 18 and later, with the modern createRoot API, automatic batching also covers updates in common asynchronous callbacks such as Promise callbacks and timers:
setTimeout(() => {
setScore((previousScore) => previousScore + 1);
setShowMessage(true);
}, 1000);
Those updates can be processed together as well. In older React setups, batching was more limited, so do not assume every asynchronous callback behaves identically across versions. If you are maintaining an older app, check the React version and root API it uses.
You usually do not need to manually batch updates. Let React handle it, and write state updates so they correctly express what the next value depends on.
Common mistakes
Expecting state to change between setter calls
setScore(score + 1);
console.log(score); // Still the value from this render
The current handler keeps its state snapshot. The new value appears in a later render.
Using a direct value for several dependent updates
If each update should build on the one before it, prefer setScore(previous => previous + 1). Repeating setScore(score + 1) repeats a calculation from the same snapshot.
Assuming one setter always means one render
React may batch multiple updates, and rendering can also be triggered by other causes. Focus on the state behavior you need; avoid using render counts as a substitute for understanding the update queue.
Practice
Add two state values to a small component: likes and hasLiked. Create a button that increases likes and sets hasLiked to true. Then add an Add three likes button using three functional updates. Watch the UI after each click and explain which values are based on the previous state.
Recap
- Batching means React groups multiple state updates and processes them together before rendering.
- It avoids extra render passes for related updates.
- Batching does not change the state snapshot inside the current handler.
- Use updater functions when one update depends on the previous queued value.
- React 18 and later with
createRootautomatically batches updates in more situations, including common asynchronous callbacks.
Next, we’ll look at What is the Virtual DOM? and how React uses render output to update the interface.
Written by
Dev Likhon
Full Stack Developer & Tech Educator
6+ years of professional development experience.
About Me
Comments
Share what you learned or ask a question.
Loading comments...