ReactInterview preparation
Intermediate·Concept·2 min read

useMemo vs useCallback?

Practice this question

Definition:

useMemo caches a calculated value between renders until its dependencies change. useCallback preserves a function reference under the same dependency idea. They can reduce repeated work or unstable props, but memoization is an optimization rather than a correctness guarantee.

Key points:

  • useMemo caches a calculated value; useCallback caches a function reference.

  • They can help with expensive calculations or stable props for memoized children.

  • They add complexity and do not stop every re-render; measure first.

  • A memoized callback can still capture stale values if required dependencies are missing.

Comparison:

PointuseMemouseCallback
PreservesCalculated valueFunction reference
Typical useExpensive filteringCallback passed to a memoized child
Dependencies changeRecalculate the valueUse a new function reference
Guarantees no re-rendersNoNo

Example — inside a component:

jsx
const visible = useMemo(
  () => items.filter(item => item.active),
  [items]
);
const select = useCallback(id => onSelect(id), [onSelect]);
  • Import these hooks from React. Use them only when the avoided work or stable identity is useful.

Interview point:

  • Explain the downstream work avoided—an expensive calculation or a memoized child's render—not just that a value is cached.
Adapted from 06_REACT_NEXTJS.md · “useMemo vs useCallback?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.