DEV Community

Discussion on: Demystifying React Hooks: useCallback and useMemo

Collapse
 
milu_franz profile image
Milu • Edited

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 :)

Collapse
 
nibble profile image
Joseph Mawa

Thanks for the feedback. I think it will be clearer when you update it.