Memoization useMemo
Question
What does useMemo do?
Hint
useMemo is for expensive calculations, not every computation.
Explanation
useMemo(calcFn, deps) memoizes (caches) the result of calcFn and only recomputes when deps change. This prevents expensive recalculations on every render. Use it for heavy computations like filtering/sorting large arrays, complex math, or deriving data. Do not overuse — memoization has its own overhead (storing deps, comparing). useMemo does not guarantee the value is preserved (React may discard cache); it is a performance hint, not a semantic guarantee.
Related Resources
Related Lessons
- Memoization
Learn memoization.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.