Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoized values with empty inputs array are known to be static #12

Open
yuchi opened this issue Apr 6, 2020 · 0 comments
Open

Memoized values with empty inputs array are known to be static #12

yuchi opened this issue Apr 6, 2020 · 0 comments

Comments

@yuchi
Copy link
Owner

yuchi commented Apr 6, 2020

In the following example the value of values should never change, and we should be able to treat it as static:

const values = React.useMemo(() => new Array(12), []);

I say “should” because the official React documentation states:

You may rely on useMemo as a performance optimization, not as a semantic guarantee.
In the future, React may choose to “forget” some previously memoized values and recalculate them on next render, e.g. to free memory for offscreen components. Write your code so that it still works without useMemo — and then add it to optimize performance.

We will skip this optimization since we cannot guarantee the semantic correctness in the long run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant