useCallback
Learn how to optimize the performance of your applications and prevent unnecessary re-renders.
We'll cover the following...
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:
- Dealing with
PureComponents
. - Functions implement their own
shouldComponentUpdate()
method. - Functions are wrapped by
React.memo()
.