react.dev
react.dev copied to clipboard
How to see that useCallback and useMemo don't recreate object (example proposition)
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,