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

The Problem: State Too High in the Tree

Why placing state at the root causes unnecessary re-renders in unrelated components.

The Problem: State Too High in the Tree

What you'll learn: How placing state at the root level causes unnecessary re-renders throughout your entire component tree.

The Root of the Problem

When you place state in a top-level component (like App or a layout component), every state update triggers a re-render of that component and all its descendants—even components that don't use that state at all.

This is one of the most common performance pitfalls in React applications.

Why This Happens

React's rendering model is straightforward: when a component's state changes, React re-renders that component and recursively re-renders all its children. It doesn't matter if those children actually use the changed state—the render cascade happens regardless.

Think of it like a fire alarm in a tall building. If you pull the alarm on the ground floor, everyone on every floor has to evacuate—even the people on the 20th floor who are nowhere near the problem.

A Common Scenario

Imagine your App component holds state for:

  • User authentication
  • Theme preferences
  • Shopping cart contents
  • Current page/route
  • Modal open/closed state

Every time any of these pieces of state change, your entire app re-renders. That includes your header, footer, sidebar, and all page content—components that likely don't care about most of these updates.

The Performance Impact

You've already learned how to measure this with the Profiler and why-did-you-render. The flamegraph will show massive cascading renders originating from your root component, with most child components rendering for no benefit.

Key Takeaway: State placed too high in the component tree forces unrelated components to re-render unnecessarily. Move state as close as possible to where it's actually used to minimize the re-render scope.