Identifying Why a Component Rendered
What you'll learn: How to use the React DevTools Profiler's "Why did this render?" feature to pinpoint exactly which props or state changes caused a component to re-render.
The Detective Work of Performance Optimization
You've recorded a profile and noticed some components are rendering frequently. But why are they rendering? Is it a prop change? A state update? A context value? The Profiler's "Why did this render?" feature acts like a detective's magnifying glass, showing you the exact evidence.
How to Use It
When viewing a flame graph or ranked chart, click on any component that rendered during a commit. The right-side panel displays detailed information, including a crucial section: "Why did this render?"
This section shows:
- Which props changed between renders (with old and new values)
- Which state changed (if managed by hooks)
- Whether the parent component rendered (causing this child to render too)
- Whether a context value changed
Reading the Evidence
If you see props.userId changed: 42 → 43, you know that specific prop change triggered the render. If you see "The parent component rendered," the component has no changed props but rendered anyway—a potential optimization opportunity (memoization, anyone?).
If nothing changed but it still rendered, you might have a new object or function reference being passed down on every parent render—classic performance pitfall.
Why This Matters
Without this feature, you'd be guessing which change caused a render. With it, you have concrete data to guide your optimization efforts. Should you memoize a callback? Split a context? Move state down? The "Why did this render?" panel tells you exactly where to focus.
Key Takeaway: The Profiler's "Why did this render?" feature removes guesswork by showing you exactly which props, state, or context changes triggered each component's re-render, making performance debugging precise and data-driven.