5 ms·
Interesting observation, but author's analysis is a way off IMHO. I use sass not because I'm "unprivileged" or there're some special legacy requirements - I use
by ivanhoe 7y ago
Interesting observation, but author's analysis is a way off IMHO. I use sass not because I'm "unprivileged" or there're some special legacy requirements - I use it because it does the job wonderfully and I don't really need to mix css with js for the type of projects that I do. Speaking of observations, most of devs that I worked with who pushed for CSS-in-JS were really either newbies who like to play with new stuff or the folks who were not that good with css and sass, and then they tend to reinvent the wheel by using very little, very basic css and lots of js to achieve the same effects that can be handled in pure css much more elegantly. Obviously this is purely anecdotal, I totally understand that for complex animations or in big systems where modularity is crucial css-in-js makes a lot of sense. As with any tool, you need to choose the right one for your particular project.
- southerntofu 7y agoThere's plenty of room for innovation using proven tech. Trying new ways can be stimulating, but it must not get in the way of accessibility, reliability and security. CSS-in-JS is the perfect example of a tech that introduces problems and complexity in almost all cases.
- wayneftw 7y agoCSS Modules give all of the benefits of CSS-in-JS plus the junior devs won’t be tempted to put 300 lines of styles in the same file as the view component. And you can still use SASS. With those benefits, I don’t see any reason to use CSS-in-JS over CSS Modules in any project.
- ivanhoe 7y agoCss modules automate the process and it's totally OK approach, but with a bit of discipline imposed on the team members you can achieve the same effect manually and avoid the weird looking foo_532xy157678 classes. You just need a proper selector naming convention in place, and then make everyone stick to it. It's not a rocket science really, you just add a unique class (usually module's name works just fine here) to every module's root element, and then in sass you wrap everything related to that module with that class and that's it, it's namespaced... add some BEM to the mix and you've got yourself fairly easy to understand and maintain sass/css with zero overhead... obviously takes some practice to unlearn yourself from using overly general selectors, but it's like learning to write testable code, you quickly learn to pay attention to bad practices...