Course contentsShow
← React
Lesson 423 of 2,39612. Rendering and BatchingFree lesson

Batching Across Components

Learn that batching works across multiple components when updates happen in the same event.

Batching Across Components

You'll learn that React's batching doesn't stop at component boundaries—updates in multiple components get batched together when triggered by the same event.

The Cross-Component Surprise

So far, you've seen batching work within a single component: multiple setState calls in one event handler trigger just one re-render. But here's the powerful part: batching works across the entire component tree.

When you click a button that updates state in both a parent component and a child component, React batches those updates together. You get a single re-render cycle, not two separate ones.

How It Works

Imagine a parent component with a button that:

  1. Calls setParentCount(parentCount + 1)
  2. Calls a child's callback that runs setChildCount(childCount + 1)

Both state updates happen during the same click event. React collects all state changes—regardless of which component they belong to—and processes them in one batch. The entire tree re-renders once, not twice.

The Mental Model

Think of batching like a shopping cart at checkout. It doesn't matter if you grabbed items from different aisles (components)—when you reach the register (end of the event), React scans everything at once. One transaction, one receipt.

This is especially important in React 18, where automatic batching extends to async operations, timeouts, and promises. Updates across components in a setTimeout callback? Still batched. In a fetch .then() handler? Batched.

Why This Matters

Without cross-component batching, cascading updates would cause performance chaos. Every state change would trigger its own render cycle, leading to visible layout thrashing and wasted computation.

Key Takeaway: React batches state updates across all components when they occur in the same event or async operation, ensuring efficient rendering no matter how your state is organized in the tree.