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

Update performant-components.md #692

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

nandorojo
Copy link

Small docs change.

Move memoization out of render scope.
Copy link
Contributor

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for this change? 🤔

@nandorojo
Copy link
Author

nandorojo commented Dec 15, 2022

Yes. The current docs are incorrect. They use memo() inside of render code. As a result, it creates a brand new component instance on every render. This defeats the purpose.

I made a sandbox to show why the current docs break the React rules of memoization.

To test it, open the console in the bottom right, and then click the Rerender button. Notice that the component wrapped with memo still logs.

Copy link
Contributor

@fortmarek fortmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation!

We can merge this once you sign the CLA, let me know if you have any issues with that 🙂

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

Successfully merging this pull request may close these issues.

3 participants