useCallback
In one line
useCallback is a Hook that returns a memoized version of a callback function, keeping the same function instance across renders.
In simple words
useCallback caches a function so it keeps the same reference across renders, as long as its dependencies don't change. const fn = useCallback(() => doSomething(a), [a]) returns the same function instance until a changes.
This is useful when you pass callbacks to memoized child components. If the parent creates a new function on every render, the child's React.memo sees a "new" prop and re-renders. Wrapping the callback in useCallback keeps the reference stable, so the memoized child can skip rendering.
useCallback(fn, deps) is equivalent to useMemo(() => fn, deps). Use useCallback for functions and useMemo for values — they are the same mechanism under the hood.
Example
const handleClick = useCallback(() => {
setCount(c => c + 1);
}, []);
// The same function reference is passed to the child every render,
// so React.memo on the child can skip re-rendering.
<MemoizedButton onClick={handleClick} />useCallback returns a stable function reference. The memoized child sees the same onClick prop and skips re-rendering.
Related terms
Related Resources
Related Lessons
- Memoization
Learn useCallback for stable function references.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.