News for hackers. Stuff that matters.
Re:Why I Write CSS in JavaScript by jmull on Monday February 18, 2019 @02:11PM (#19193336)
I agree CSS has problems. What I don't see is how styles-in-JS addresses them.

Very typically, for a given app and page the styles of individual elements and components are not independent. They also depend the app theme, app section, layout area, component group, etc. The element fits the component. The component fits into the section, the section fits into the page. The specific relationships in a particular case are different of course. Styles are visual and the idea that a component on a page has nothing visually to do with the rest of the page is wrong.

The typical scoping rules of programming languages doesn't fit that well here.

To the extent some styling solution encourages you to treat styles that are dependent as independent, that's not a good or useful thing.

Re:Why I Write CSS in JavaScript by allover on Monday February 18, 2019 @02:20PM (#19193408)
A lot of CSS-in-JS libraries provide a theming solution, e.g. [1], so it's not an 'either/or'.

(You can also relatively easily implement your own, because JS :))

[1] https://www.styled-components.com/docs/advanced#theming

Re:Why I Write CSS in JavaScript by jmull on Monday February 18, 2019 @02:47PM (#19193712)
Sure.

My point is, when it comes to visual styling, you inherently have a shared visual context.

The post I was replying to was concerned with the "global" nature of CSS.

I'm pointing out that this is inherent to the problem space. You have to deal with it whether you use CSS, code or any other mechanism to style.

Re:Why I Write CSS in JavaScript by allover on Tuesday February 19, 2019 @02:31PM (#19201967)
Nobody in the CSS-in-JS world is disputing that a global theme is useful, just that having no choice but to have all your selectors be global is not so great.