Please, Please Don’t Use “CSS in JS”
Alex Sharp

I see what you are trying to say here and while I can agree on some aspects, I personally see no harm in using CSS in JS. You know why we have CSS in JS? Because conventional CSS is a mess. The one global scope for all CSS is a pain in the butt. If you have ever worked on a large scale application, especially when teams from different timezones are working on the same application, you see first hand the issues that arise when someone checks in some CSS and it messes up your newly committed feature.

I get it, using CSS in Javascript feels dirty, but once you realise that it solves some of the biggest issues you will encounter working on a web application, you realise why such a concept exists and why Facebook and other companies are adopting this approach. It does not exist because developers are lazy, it exists because the way CSS works at present is fundamentally broken.

As for your comment regarding writing your app in components, the project I am working for now (for a small startup) is in components, the startup I worked at prior was an Angular/React app and once again, components. The last 3 freelance projects I did were written in a component based fashion. Components make sense in all sized applications. They promote encapsulation, they are easier to work with and reduce the amount of merge conflicts you will encounter when working in a team of more than 5 developers. A component workflow is not just for Facebook.

As for the extension of language and lockin, that’s arguable. You are still using regular CSS, you are just writing it in a different way. Just because “float: left” is being used inline in your Javascript doesn’t mean you’re using a different subset, at the end of the day, the CSS gets interpreted the same way browser based CSS does, it has just been defined differently. How is it any different than developers using SASS or Stylus to write their CSS? They allow you to write CSS that needs an additional parser step before it can work and if you remove the pre-processor you need to go back and unlock your code.

Overall it was a great rebuttal against CSS in Javascript, but at the end of the day, I think this is purely an opinion piece not really backed by any solid facts.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.