Course contentsShow
← React
Lesson 2312 of 2,39650. Performance: Optimization TechniquesFree lesson

Identifying Over-Hoisted State

How to spot state that's higher than it needs to be by analyzing which components actually need it.

Identifying Over-Hoisted State

What you'll learn: How to spot state that's placed higher in your component tree than necessary, causing unnecessary re-renders downstream.

The Core Problem

State that lives in a parent component triggers re-renders of all its children whenever it changes—even children that don't use that state. "Over-hoisted" state is when you've placed useState (or similar) in a component that's an ancestor to many components, but only one or two of those descendants actually need it.

How to Spot It

Look for these warning signs:

1. Wide Re-render Radius
When state updates, do dozens of components re-render, but only one actually displays the data? That's a red flag.

2. Distance Between State and Usage
Is your state defined 3+ levels above the only component that reads it? Ask yourself: could it live lower?

3. Prop Drilling Through Uninvolved Components
If you're passing state through multiple layers of components that never use it themselves, you've likely hoisted too high.

4. Profiler Evidence
The React DevTools Profiler will show many components rendering when state changes. Filter by "why did this render?"—if most say "parent rendered" but don't use the changed data, that's over-hoisting.

The Mental Check

Ask: "What's the lowest common ancestor of all components that need this state?" That's where it should live—not higher.

Analogy: It's like storing milk at your neighbor's house instead of your own fridge. Sure, it's refrigerated, but now every time someone opens their fridge, you're involved too.

Key Takeaway: State should live at the lowest point in the tree where all components needing it can access it—analyze re-render scope and usage patterns to find the right level.