Loading...
Loading...
CSS-in-JS is an approach to component styling where CSS is written directly in JavaScript files, often using libraries like styled-components, emotion, linaria, stitches and others.
This approach provides several advantages: scoped styles, dynamic styles, isolation, theme support, etc.
But it also has drawbacks, especially if used without understanding the pitfalls.
Every time a component renders, the library may recreate classes or styles. This is especially critical in large lists or with frequent UI updates.
Solution:
React.memo / useMemo.css functions for caching.CSS-in-JS libraries add their runtime to the JavaScript bundle, especially if used without optimizations.
Solution:
vanilla-extractastroturflinariababel plugin, babel macro, vite plugin, webpack loader).CSS-in-JS can cause hydration issues or missing styles on first render.
Solution:
Recommendation:
Choose CSS-in-JS libraries wisely considering your project requirements and performance constraints.