Course contentsShow
← React
Lesson 2231 of 2,39649. Performance: Identifying ProblemsFree lesson

What why-did-you-render Detects

Learn how this library identifies avoidable re-renders caused by props and state that didn't actually change.

What why-did-you-render Detects

You'll learn exactly what kinds of avoidable re-renders the why-did-you-render library catches and reports.

The Core Problem It Solves

By now you've used React DevTools Profiler and console logs to manually investigate why components re-render. But there's a library that automates this detective work: why-did-you-render (often abbreviated as WDYR).

This library instruments your React components and watches for a specific anti-pattern: components that re-render even though their props and state didn't meaningfully change. It catches the subtle bugs where props look different to JavaScript's comparison (reference inequality) but contain the same actual values.

What It Detects

WDYR identifies re-renders caused by:

1. Props with Different References, Same Values

When a parent creates a new object { id: 5, name: 'Alice' } on every render instead of memoizing it, the child receives a "new" prop that's actually identical content-wise.

2. State Updates That Don't Change Value

Calling setState(3) when state is already 3, or setting state to a new object that's deeply equal to the old one.

3. Inline Function Props

Passing onClick={() => doSomething()} creates a new function reference every render, triggering child re-renders even when the behavior is identical.

How It Reports Findings

When WDYR detects an avoidable re-render, it logs detailed console messages showing:

  • Which component re-rendered unnecessarily
  • Which props/state changed by reference but not by value
  • Before/after values for comparison

Think of it as a watchdog that barks only when it sees your component doing extra work for no reason—freeing you from manually checking every render with Profiler.

Key Takeaway: why-did-you-render automatically detects and logs components that re-render due to reference inequality in props or state, even when the actual values haven't changed—catching performance bugs you might miss manually.