3 ms·
I think you're missing an important point. Not all CSS in JS solutions attach styles as inline styles. Some of them, such as Styled Components [1] and Emotion [
by Cu3PO42 8y ago
I think you're missing an important point.
Not all CSS in JS solutions attach styles as inline styles.
Some of them, such as Styled Components [1] and Emotion [2] (and many more) will actually generate proper CSS Stylesheets and attach them to the document, thereby enabling usage of all CSS features—including, for example, pseudo-classes.
This may incur some additional runtime cost when the page loads (which is definitely nothing to dismiss), but should be (roughly) as performant as "native" styles after.
They still come with other disadvantages (and advantages), so I'm not saying you should definitely use them, but maybe you should take a look at some implementations you might not have seen yet.
Personally I arrived at the conclusion that they're not for me and that I'll just stick to SCSS.
[1] https://www.styled-components.com https://www.styled-components.com
[2] https://emotion.sh https://emotion.sh
- danShumway 8y agoYou're right, I didn't know that there were solutions that took this approach! Yeah, I would agree that dynamically attaching stylesheets is better than using the default React model for inline styles. I'd still be worried about the performance implications, but this might address a lot of my concerns.