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

Taught in

References