How does useMemo differ from useCallback?
Both useMemo
and useCallback
are used for memoization in React, but they serve different purposes:
useMemo
memoizes the result of a function, meaning it stores the result of a computation.useCallback
memoizes a function itself, ensuring that a function reference is stable and does not change unless its dependencies change.
Can we use useMemo and useCallback interchangeably?