useCallback

Learn how to optimize the performance of your applications and prevent unnecessary re-renders.

What is useCallback()?

The useCallback() Hook can be used to optimize the performance of an application. It receives a function and then creates a unique identity of that function, which will remain active until the dependencies of the Hook itself change.

This is important becasue we need to provide the same reference to a function when:

  1. Dealing with PureComponents.
  2. Functions implement their own shouldComponentUpdate() method.
  3. Functions are wrapped by React.memo().
...