Skip to content

Memoization

In one line

Memoization is an optimization technique that caches the result of expensive computations or component renders to avoid repeating work.

In simple words

Memoization means "remember the last result and reuse it if the inputs haven't changed." In React, three tools provide memoization:

  1. React.memo — wraps a component so it only re-renders when its props change (shallow comparison).
  2. useMemo — caches a computed value, recalculating only when dependencies change.
  3. useCallback — caches a function definition, returning the same instance when dependencies are unchanged.

Memoization trades memory for speed: you use extra memory to store cached results, but avoid expensive recomputation. Only memoize when you have measured a performance problem — premature memoization adds overhead and complexity for no benefit.

Example

jsx
const expensiveValue = useMemo(() => {
  return data.filter(x => x.active).map(x => x.value);
}, [data]);

// Only recomputes when `data` changes, not on every render.

useMemo caches the filtered and mapped result. If data hasn't changed, React reuses the cached value instead of recomputing.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary