Hacker News new | ask | show | jobs
by black-alert 2681 days ago
> Why don't we have more : "We tried it, it is the worst, especially for products which lifespan is more than two months"

Because that last sentence is just rubbish, CSS in JS is great. I'm using it for large projects already 4 years. If your experience is bad you must be doing something wrong. CSS in JS is almost the same as working with (S)CSS, except for extra power to control dynamic elements without having to juggle with classnames.

3 comments

Clearly when somebody has a bad experience, they are just doing it wrong.

Or perhaps there's something to it, and the idea is not as good as one might claim it to be.

Or they are solving other problems and that's the reason why one believes a solution is bad and another one thinks it's the best.
Juggling pre-compiled gpu stuff (css classes) exists for a reason.

Scss is like css.

Jss is css + unnecessary abstraction on top of css + unnecessary memory and cpu cycles + writing part of css rules inside flow control (which can turn into js in css in js.

GPU facing languages have always been ugly and not just in this industry. But they are like that because of their nature. Making them friendlier is always welcome, but replacing them with cpu stuff defeats the whole purpose of a gpu.

> CSS in JS is almost the same as working with (S)CSS, except for extra power to control dynamic elements without having to juggle with classnames.

I completely disagree.

Time and effort creating frontend design systems, will result in a set of CSS files .. but will also enable efficiency, flexibility, accessibility, maintainability and extensibility. These qualities just aren't going to be as available if you use CSS in JS.

There's nothing expressly better about SCSS over CSS in JS that you have demonstrated.

CSS In JS is mostly using similar structure, but often the JS dom interface naming... so fontFamily instead of font-family. It's also far easier to introduce codified variant functions or variable injection in JS than it is in SCSS.

I'm not saying don't use SCSS if it fits your model better... I've been very happy using react-jss via material-ui ... I've extended the baseline theme and that gets used throughout the application with each component defining its' styles that get injected.

Sharing can be a little more awkward, but it's easy enough, just call the same style method(s), or extend the baseline theme that gets injected.

The only thing you mention that might be better with (S)CSS directly would be efficiency and even that's relative. You can absolutely do all the rest with CSS in JS.

There have been many philosophical (and practical) conversations over the years that have lead to the development of a rich and varied frontend development ecosystem.

If you're building a frontend system, you need to consider the overall (macro) view, as well as the detail oriented (micro) view.

It's very difficult to do this with CSS in JS because of the compromises that need to be made to work in this way.