Mitigating Cost: Lift State Down
You'll learn how to minimize re-render overhead by moving controlled input state into the smallest component possible.
The Problem: Parent Re-renders Cascade
When you keep input state in a parent component, every keystroke triggers a re-render of that parent and all its children—even children that have nothing to do with the input. This creates an unnecessarily large re-rendering subtree.
function App() {
const [name, setName] = useState('');
// Every keystroke re-renders App AND both children below
return (
<div>
<input value={name} onChange={(e) => setName(e.target.value)} />
<ExpensiveChart /> {/* Re-renders on every keystroke! */}
<LargeTable /> {/* Also re-renders! */}
</div>
);
}
The Solution: Extract a Smaller Component
Move the state to the smallest component that needs it. If only the input and a nearby label care about the value, wrap them in their own component:
function NameInput() {
const [name, setName] = useState(''); // State lives here now
return <input value={name} onChange={(e) => setName(e.target.value)} />;
}
function App() {
// Now keystrokes only re-render NameInput—not App or siblings
return (
<div>
<NameInput />
<ExpensiveChart /> {/* Never re-renders from typing */}
<LargeTable />
</div>
);
}
The Analogy
Think of re-renders like dominoes. When state lives high in the tree, you knock over a tall stack with every keystroke. Moving state down is like creating a smaller, isolated domino set—only that tiny section falls.
When to Apply This
- Large component trees with expensive siblings
- Forms where different fields are independent
- When React DevTools Profiler shows unnecessary re-renders
Key Takeaway: Move controlled input state to the smallest component that needs it—this shrinks the re-rendering subtree and prevents unrelated components from re-rendering on every keystroke.