Lift Content Up: Practical Example
What you'll learn: How to refactor a real component by extracting slow logic into a wrapper and passing fast-rendering content as children.
The Problem Scenario
Imagine you have a <Dashboard> component that renders a slow, data-heavy chart and some simple UI controls. Every time you click a button to change a filter setting (updating state), the entire dashboard re-renders—including that expensive chart—even though the chart's data hasn't changed.
function Dashboard() {
const [filter, setFilter] = useState('all');
// Expensive component that doesn't need filter
return (
<div>
<ExpensiveChart data={chartData} />
<button onClick={() => setFilter('active')}>
Active Only
</button>
<FilteredList filter={filter} />
</div>
);
}
Every setFilter call re-renders <ExpensiveChart>, wasting time.
The Lift Content Up Solution
Step 1: Create a wrapper component that holds only the state:
function DashboardWrapper() {
const [filter, setFilter] = useState('all');
return (
<Dashboard filter={filter} setFilter={setFilter} />
);
}
Step 2: Make the original component accept the slow content as children:
function Dashboard({ filter, setFilter, children }) {
return (
<div>
{children} {/* ExpensiveChart passed from outside */}
<button onClick={() => setFilter('active')}>
Active Only
</button>
<FilteredList filter={filter} />
</div>
);
}
Step 3: Pass the expensive chart as children from the wrapper:
function DashboardWrapper() {
const [filter, setFilter] = useState('all');
return (
<Dashboard filter={filter} setFilter={setFilter}>
<ExpensiveChart data={chartData} />
</Dashboard>
);
}
Now when filter changes, only <Dashboard> re-renders. The children prop (the chart) keeps the same reference—React skips re-rendering it automatically.
Key Takeaway: By moving state into a parent wrapper and passing static content as children, you isolate re-renders to only the components that actually depend on that state—no memo needed.