Batch Updates
In one line
React batches multiple setState calls into one re-render — automatic in React 18, even in async code.
In simple words
Batch updates means React groups multiple state changes into a single re-render. Instead of re-rendering after each setState call, React waits and re-renders once after all updates.
React 18 enables automatic batching — it batches updates everywhere, including async callbacks (setTimeout, promises, native event handlers). Before React 18, batching only happened in React event handlers.
This means: if you call setState three times in a row, React renders once, not three times. This is a major performance win.
You can opt out with flushSync if you need an immediate render (rare).
Example
import { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
const [label, setLabel] = useState("Ready");
function handleClick() {
// These are batched — one re-render, not two
setCount(c => c + 1);
setLabel("Updated");
}
async function fetchData() {
const data = await api.get();
// React 18: also batched in async!
setCount(data.count);
setLabel(data.label);
}
return <button onClick={handleClick}>{label}: {count}</button>;
}Both setState calls in handleClick are batched into one render. In React 18, the async fetchData updates are also batched automatically.
Common confusions
Confused with: useTransition
The difference: Batching groups multiple updates into one render — it's about efficiency. useTransition marks updates as low-priority — it's about responsiveness. Batching reduces render count; useTransition allows interruption. They work together but solve different problems.
Related terms
Related Resources
Related Lessons
- React Performance
Batch updates.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.