Performance & DOM · 8 min read · Intermediate
Memoization & Render Performance
Know when React re-renders, measure before optimizing, and use useMemo and useCallback purposefully.
What you'll learn
- Understand React's default render behavior (parent renders -> children render)
- Cache genuinely expensive derived computations with useMemo
- Avoid premature memoization everywhere when simple renders are already sub-millisecond
useMemo(() => compute(items), [items]) caches the result of an expensive calculation (like filtering/sorting 20,000 rows) until its dependencies change. useCallback(fn, [deps]) stabilizes a function reference passed to memoized children or effect dependencies.
Fill-in-the-Blank Exercise
Memoize Expensive Sort
Cache the sorted copy of rows so it only recalculates when rows changes.
const sorted = (() => [...rows].sort((a, b) => b.score - a.score), []);Live Memoization Demo
Cache Hit vs. Cache Miss
Live Result
Console Output
No console output yet. Try calling console.log(...) in JS.
Check Your Understanding
Score: 0 / 1
1. When is useMemo most genuinely useful?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.