Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are styled components memoized?

Just wondering if styled components are memoized or whether I can/need to do this independently? Specifically, are the props that are passed into the template literal memoized, such that the styled component is only re-rendered if the value of the props change?

If it needs to be done independently, how do you do this?

like image 851
JoeTidee Avatar asked Nov 07 '22 05:11

JoeTidee


1 Answers

I checked the source code and it seems that it hashes the resulting CSS and only updates the page style when the hash is not already present. This should prevent changes to the DOM when the props do not change.

The component itself is not memorized. You could wrap with with React.memo() to achieve that. But you might run into issues when the theme changes.

like image 79
Nappy Avatar answered Dec 19 '22 17:12

Nappy