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

Use memo: true flag with SVGR #9422

Open
vihanb opened this issue Aug 5, 2020 · 2 comments
Open

Use memo: true flag with SVGR #9422

vihanb opened this issue Aug 5, 2020 · 2 comments

Comments

@vihanb
Copy link

vihanb commented Aug 5, 2020

Is your proposal related to a problem?

My situation is, I have components that pass an SVG icon to another component, because the SVG instance always changes, I have a lot of unnecessary re-renders (e.g. <MyBigComponent icon={<MySvg />} />.

Describe the solution you'd like

SVGR has a memo option: https://react-svgr.com/docs/options/#memo which wraps all SVG components in React.memo. This would resolve the issue above. Additionally, I can't really think how memo would break existing projects so I believe it would be a helpful addition to create-react-app.

Describe alternatives you've considered

Alternative solutions that come to mind include something like useMemo(() => <MySvg />, []) but something about that feels wrong.

@eddiemonge
Copy link
Contributor

but something about that feels wrong.

But thats exactly what setting that option does. Setting that for everyone seems overkill. It adds additional processing because of the additional function and watch calls that memo uses.

@vihanb
Copy link
Author

vihanb commented Aug 5, 2020

Surely a shallow props comparison is much less of a performance hit than the reconciler comparing the entire SVG object (especially for complex paths and illustrations).

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

No branches or pull requests

2 participants