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

When React.memo Actually Matters

Identify scenarios where memoization provides measurable benefit vs premature optimization noise.

When React.memo Actually Matters

What you'll learn: How to distinguish between performance problems React.memo genuinely solves and expensive premature optimization that clutters your code.


The Core Principle

React.memo prevents a component from re-rendering when its props haven't changed. But wrapping every component in React.memo is cargo-cult programming. The critical question is: does this component's re-render cost enough to justify the memoization overhead?

Memoization itself has costs: React must compare props on every parent render, and you must maintain stable references (with useMemo/useCallback). This adds complexity and cognitive load.

When It Actually Matters

Measurable benefit scenarios:

  1. Heavy component trees - A component that renders dozens or hundreds of children
  2. Expensive render logic - Components with complex calculations, heavy string processing, or canvas operations
  3. High-frequency updates - A parent that updates rapidly (animations, scroll handlers) but the child's props rarely change
  4. List items with stable data - Rendering large lists where most items don't change between renders

When It's Premature Optimization

  • Simple presentational components (buttons, labels, cards)
  • Components that always receive new props anyway
  • When you haven't profiled and confirmed a problem exists
  • When the parent rarely re-renders

The Decision Framework

  1. Profile first with React DevTools
  2. Identify components with high render frequency and non-trivial render time
  3. Apply React.memo only to those components
  4. Confirm improvement with another profile

Key Takeaway: React.memo is a scalpel for specific performance bottlenecks identified through profiling, not a blanket solution to sprinkle everywhere. Optimize components that are slow and render often—ignore the rest.