Re: “‬How does writing CSS in JS make it any more maintainable?”
One major problem I&#x27;ve run into is that CSS in JS usually lacks support for pseudo-classes and browser breakpoints.<p>The recommendation from communities in frameworks like React is that you should use JS and extra elements to polyfill that behavior. This is both less performant and less semantic. It really doesn&#x27;t work particularly well if you&#x27;re used to leveraging CSS in powerful ways.<p>Stuff like :first-of-type, sibling selectors, and so on are extremely useful. You give them up when you start manually attaching inline styles, and both JS performance and JS complexity to replicate those features will pretty much always be worse.<p>Doing animations in JS is usually a step too far even for the React community, so the recommendation I see there is often that you should define normal CSS classes and dynamically apply them. But now you&#x27;re starting to mix CSS and CSS-in-JS, which is do-able, but can come with own set of subtle consequences. It also significantly lessens the benefit of CSS-in-JS, which is that you get to stop worrying about conflicts. It&#x27;s not a dealbreaker, but it means you&#x27;re somewhat back to managing the same name conflicts and typos that you were before.<p>I started out as much more open to CSS in JS than I am now. I was cautious about it and usually avoided it for personal projects. After doing a little bit more work on projects that use this pattern, I now feel like it&#x27;s <i>probably</i> a bad idea, and advise other people to be careful about using it, even if I&#x27;m not willing to take a hard stance quite yet.<p>It&#x27;s not that component-based CSS is a bad idea, I&#x27;m much more friendly now towards BEM than I used to be. And it&#x27;s not even that CSS outside of JS doesn&#x27;t have problems (the authors point about loading order is a particularly good example, albeit one that really shouldn&#x27;t be coming up very often in a component based world. Also yeah, testing). I&#x27;m just less convinced that CSS in JS is a sufficiently scalable solution to those problems, or that it doesn&#x27;t have significant problems of its own.