React useCallback

The useCallback hook for memoizing functions.

React useCallback Hook

The React useCallback Hook returns a memoized callback function.

This allows us to isolate resource intensive functions so that they will not automatically run on every render.

The useCallback Hook only runs when one of its dependencies update.

Example

const memoizedCallback = useCallback(() => {
  doSomething(a, b);
}, [a, b]);