useCallback
The React hook that returns the same function object between renders until one of its dependencies changes.
In more detail
It keeps a callback prop stable so a memoized child or an Effect that depends on it does not re-run needlessly. It is equivalent to useMemo returning a function.
Example
const inc = useCallback(() => setVal((c) => c + step), [step]);Related terms
- useMemo — The React hook that caches the result of a calculation between renders and recalculates only when its dependencies change.
- reference equality — Comparing two references to see whether they point to the very same object, rather than to objects with equal contents.
- React.memo — A React function that wraps a component so it skips re-rendering when its props are shallowly equal to the previous ones.
- dependency array — The array of values given to hooks such as useEffect, useMemo and useCallback that tells React when to re-run them.
Taught in
- Custom Hook Composition: Encapsulating Reactive Logic — React 19 & Modern Component Architecture
- Render Diagnostics: Profiling Re-Renders with React DevTools — React 19 & Modern Component Architecture
- React.memo, useMemo, And useCallback: Optimization Costs — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture