react.dev icon indicating copy to clipboard operation
react.dev copied to clipboard

How to see that useCallback and useMemo don't recreate object (example proposition)

Open 4m1n83 opened this issue 2 years ago • 0 comments

Hello,

I think this could be added to the documentation. So the question is: how to "see" that useCallback and useMemo memoize objects? Since we can't see the memory address of the objects created in the heap. Answer: by creating recreate a Function "class" and an Object "class" which has a unique ID for each instantiation. The details of the implementation can be found here: https://codesandbox.io/s/musing-sun-79d1gg?file=/src/App.js

Kr,

4m1n83 avatar Mar 02 '23 15:03 4m1n83