Thanks for the article. The illustrations make it easy to follow.
useCallback hook returns the same instance of the function being passed instead of creating a new one when a component re-renders. This occurs only when the dependencies passed to the second parameter change.
I think the above statement is a little confusing. What occurs when the deps change? Is it:
Thanks for the article. The illustrations make it easy to follow.
I think the above statement is a little confusing. What occurs when the
depschange? Is it:Hi Joseph! Thanks for your question... I can see how this statement is confusing.
Let’s take a look at useCallback’s structure. It receives two parameters:
(#1) a function
(#2) an array of dependencies
useCallback returns the same instance of the function being passed (parameter #1) instead of creating a new one every time a component re-renders.
It creates a new instance of the function being passed (parameter #1) only when the array of dependencies (parameter #2) changes.
Does this make sense? I will update my post to make sure this definition is more clear. Thanks for your feedback :)
Thanks for the feedback. I think it will be clearer when you update it.