LESSON 09 / 12·2 min readIntermediate

useMemo vs useCallback?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

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.

Important ideas

  • 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.
PAUSE & RECALL

Can you explain it without the notes?

useMemo vs useCallback?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

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.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Explain the downstream work avoided—an expensive calculation or a memoized child's render—not just that a value is cached.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: When do I use Context, useReducer or a custom hook?

Adapted from 06_REACT_NEXTJS.md · “useMemo vs useCallback?”. Examples are study fragments; framework behavior can depend on your version.