4 ms·
CSS in JS isn't CSS. It's just SS. It ignores the best part of the language; the cascade.
by pault 8y ago
CSS in JS isn't CSS. It's just SS. It ignores the best part of the language; the cascade.
- deleted 8y ago[deleted]
- charrondev 8y agoOr the worst from my point of view. CSS rots more than any other code in a front end codebase and the methods for static analysis are incredibly limited. Refactoring and static analysis tools are incredibly limited or nonexistent for plain CSS or SCSS (when talking about the barriers between HTML and the stylesheet). We do all of our new views and stylesheets using React, TypeScript, and Typestyle. As a result we can expose much controlled methods of theming and have a compiler enforced link between variables, selectors, and their usages. We can refactor easily. We can catch simple typos at compile time instead of runtime, and validate them more easily in CI.
- pault 8y ago> have a compiler enforced link between variables, selectors, and their usages. That sounds interesting. Can you describe that in more detail?
- rmrfrmrf 8y ago1) it doesnt ignore it 2) anyone claiming not to have a single `style=""` attribute (which is almost as specific and 1000x less maintainable) in their code is lying
- pault 8y agoI will swear on my life that I haven't used a style attribute in the last five years. Since I started using BEM for namespacing I have had a very easy time keeping my CSS clean and maintainable. I won't deny others their opinions, though.
- chrisweekly 8y agoBEM is a decent convention for old-school, global document styling, in the absence of scope. But it's also manual, error-prone, and verbose, making it a poor substitute for actual namespacing provided by components. I sympathize with your resistance to css-in-js; I've been doing webdev since 1998 and only really embraced it in the last couple years. I'm reminded of quotes like "The difficulty lies not so much in new ideas, but in escaping the old."
- pault 8y agoFair enough. I felt the same way about JSX when it came out so maybe I need to give it another look. :)
- mercer 8y agoI think BEM was the point where I decided to give up and accept CSS in my JS.
- chrisweekly 8y agoThe cascade was great for HTML in the absence of scope, which is to say in the age of documents. It's a reasonable approach to dealing with all the problems inherent in managing global state. But globals suck. In the age of components it makes little sense to cling to the cascade as if it were more than a means to an end.