How to see that useCallback and useMemo don't recreate object (example proposition)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 11.8k
- Forks
- 7.9k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 11
Description
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,
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by opening the linked CodeSandbox and reviewing its src/App.js example to understand the proposed demonstration. Then inspect the React documentation for a suitable location and determine whether the example clearly explains memoization; done means producing an agreed documentation change or a concrete placement proposal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100