4 ms·
It’s used in order to prevent redundant rerender to child components. When passing to a child component a function you’ve created inside functional component it
by null_deref 2y ago
It’s used in order to prevent redundant rerender to child components.
When passing to a child component a function you’ve created inside functional component it’s get recreated because JS doesn’t keep references to a function created inside a function, thus making your child component rerender because a prop has changed.
This example actually really corresponds with this post comments, the need for useCallback have only emerged after the move from class components, because private methods you create in a class do not get recreated at each render