DEV Community

Discussion on: Let's Take a Look at CSS in JS with React in 2019 - CSS & Inline Styling

Collapse
 
eatsjobs profile image
Pasquale Mangialavori

You can put your style object outside the render function. Or as static property of the function/class. otherwise you are gonna to recreate the same style each time

Collapse
 
phizzard profile image
Phil Tietjen

Thanks for commenting, You're totally right Pasquale! Ideally you can store your style variables really anywhere you want to and import them into your components.

However I did want to just show off a simple example that can also show props affecting styles.

We can also use useMemo to avoid recreating the same style on every render but I figured it was just a little out of scope for what I wanted to show :)