reactjs / reactjs/react.dev

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

Open
#5,640 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.