Course contentsShow
← React
Lesson 955 of 2,39624. React.memoFree lesson

Splitting Components to Contain Updates

Extract frequently-changing UI into its own component so updates don't trigger expensive siblings.

Splitting Components to Contain Updates

What you'll learn: How to isolate frequently-changing state into separate components so their updates don't force expensive siblings to re-render.

The Problem: State Hoisted Too High

When state lives in a parent component that renders multiple children, every state update re-renders all those children—even if only one child actually cares about that state. This is wasteful when some children are expensive to render.

The Solution: Split and Contain

Instead of keeping all state in one parent, extract the frequently-updating UI into its own component. Move the state down with it. Now only that small component re-renders on updates, while its siblings stay untouched.

Think of it like noise-canceling headphones: you contain the "noise" (rapid re-renders) within one room (component) so it doesn't disturb the rest of the house (expensive siblings).

How It Works

Before splitting, a parent might render an expensive chart, an expensive table, and a text input. Every keystroke in the input re-renders the chart and table unnecessarily.

After splitting, the input and its state live in a dedicated SearchInput component. The parent only renders SearchInput, the chart, and the table. Now keystrokes re-render just SearchInput—the chart and table never notice.

This is often more effective than React.memo because you avoid the problem entirely rather than paying for memo's comparison checks on every parent render.

When to Use This Pattern

  • You have a parent rendering multiple heavy children
  • One piece of state updates frequently (typing, sliding, hovering)
  • Only one child needs that rapidly-changing state
  • Moving the state down doesn't complicate your logic

Key Takeaway: Split frequently-updating UI into its own component to contain re-renders at the source—it's simpler and cheaper than sprinkling memo everywhere.