At react docs I've read
Pass an inline callback and an array of dependencies. useCallback will return a memoized version of the callback that only changes if one of the dependencies has changed. This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders (e.g. shouldComponentUpdate).
That's fine, we need to prevent unnecessary renders for the childs, but for the current component that is using the useCallback
, what useCallback
really offer?
As far as I know useCallback
is about preventing the current component re-renders from creating the same function over and over again(correct me if I'm wrong) and it will keep a reference to the same function (without creating a new one) as far as the dependency array include the same references.
Is it right? Or we have something deeper?
I've checked this great answer but it's talking about preventing (childs) re-renders, I'm looking for what useCallback
means for the current component.