Detecting New Object/Function References
What you'll learn: How to spot when inline object literals or arrow functions in JSX cause unnecessary child component re-renders.
The Hidden Performance Killer
When you pass an inline object literal (like style={{ color: 'red' }}) or an inline arrow function (like onClick={() => handleClick()}) as a prop to a child component, JavaScript creates a brand new reference on every render. Even if the content is identical, the reference is different—and React sees this as a "new" prop.
If the child component is wrapped in React.memo, it will still re-render because React.memo compares props by reference. Two objects with identical content are not === equal in JavaScript.
Real-World Example
// ❌ Creates new object reference every render
<ExpensiveChild style={{ color: 'red' }} />
// ❌ Creates new function reference every render
<ExpensiveChild onClick={() => console.log('clicked')} />
Even when ExpensiveChild is memoized, these inline creations break the memoization. It's like giving someone a "new" business card every time—even though the information is the same, it's a different physical card.
How why-did-you-render Helps
The why-did-you-render library specifically flags these issues in the console:
ExpensiveChild re-rendered because of prop changes:
style: {} !== {} (different objects, equal by value)
onClick: () => {} !== () => {} (different functions)
This output tells you exactly which props are causing unnecessary renders due to reference inequality, even when the values are functionally identical.
Key Takeaway: Inline object literals and arrow functions in JSX create new references on every render, breaking React.memo optimizations—use why-did-you-render to spot these issues quickly before manually optimizing with useMemo or useCallback.