HomeReact
Chapter 11

11 β€” useMemo, useCallback & React.memo

Performance hooks that let you skip unnecessary work. But they have costs β€” use them wisely.

The Three Tools

ToolWhat It MemoizesUse Case
useMemo(fn, deps)A computed valueExpensive calculations
useCallback(fn, deps)A function referenceStable callbacks for memo'd children
React.memo(Component)A component's renderSkip re-render when props haven't changed

When to Use (and When NOT to)

βœ… Use Memoization When:

  • Filtering/sorting large lists (1000+ items)
  • Complex mathematical computations
  • Passing callbacks to React.memo-wrapped children
  • Context values (to prevent consumer re-renders)

❌ Don't Use When:

  • Simple calculations (adding two numbers)
  • The component rarely re-renders anyway
  • You're not sure if it helps (measure first!)
  • The value is a primitive (React already optimizes)

> Rule: Every useMemo and useCallback has overhead (dependency comparison). If the computation is cheap, memoization is slower.

File

  • memoization.tsx β€” useMemo, useCallback, React.memo, performance measurement, when to use, anti-patterns