How does useCallback prevent child component re-renders?
When a memoized function created with useCallback
is passed as a prop, React's React.memo
can use shallow comparison to determine if the prop has changed.
If the function reference remains the same (thanks to useCallback
), the child component does not re-render.