r/learnreactjs • u/its-procodester • Aug 15 '24
Question Wrap SVG in React.memo?
Is it beneficial to wrap an SVG component in React.memo to prevent unnecessary re-renders, considering they are pure components?
2
Upvotes
View all comments
Show parent comment
1
u/[deleted] Aug 25 '24
It doesn't matter if it's causing issues. Everyone should attempt to write performant code.
Let's say you have a controlled input component that is adorned with an error or checkmark icon, depending on whether or not there is an error in state. The input component is going to re-render every single time the value changes. Why wouldn't you memoize the svg?