Home
← All questions

Difference between useCallback and useMemo in React

MediumPremiumReact

React interview practice: When to use useCallback vs useMemo and how they relate.

Answer

Both memoize across renders based on a dependency array; they differ in what they return:

  • useMemo(fn, deps) returns the memoized value that fn produces (e.g. an expensive computation or a stable object/array).
  • useCallback(fn, deps) returns the memoized function itself. useCallback(fn, deps) === useMemo(() => fn, deps).
Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium