3 ms·
CSS 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
by wayneftw 7y ago
CSS 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...