Skip to content
React·Intermediate·Coding·1 min read

When should useMemo and useCallback be used?

Short interview answer

They are performance optimizations for avoiding measured expensive recomputation or stabilizing identity across a meaningful memoization boundary. They add dependency and memory complexity, so do not use them as correctness tools or reflexively wrap every value.

Example

JSX
// Worth it: expensive derivation, or identity a memo child depends onconst sorted = useMemo(() => bigList.slice().sort(compare), [bigList]);const onSelect = useCallback((id) => dispatch(select(id)), []);

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to React hooks

Related questions