Live data from Hacker News

Why I Write CSS in JavaScript

mxstbr.com

141–150 of 255 posts

Re: Why I Write CSS in JavaScript

#141
CSS === Cascading Style Sheets

In the context describe in the article, there is nothing cascading, and there are no sheets.

What he / she is doing is going back to the late 90's and inlining all the style'ing. I'm not judging the technique, simply pointing out that it's not actually CSS.

Re: Why I Write CSS in JavaScript

#142
post #128

Imagine a programming language that only had global variables. You have to carefully name your variables using complicated conventions in order to avoid any conflicts or unexpected behavior. Even your functions don't have local variables; there is no lexical scoping. Any function can overwrite or mutate what any other function is doing inside. There is no real encapsulation. After you've done this perfectly, your app…

CSS isn't a programming language, that is the fundamental difference and explains a LOT of the debate surrounding it.

Does not classifying it as a programming language help this situation at all?

Re: Why I Write CSS in JavaScript

#143
What I don't like about css-in-js is how it makes things really hard (or even impossible) for endusers who may want to use an extension like stylus or tampermonkey to modify the site styling or behaviour.

Re: Why I Write CSS in JavaScript

#144

Earlier quoted context omitted.

> I never was able to learn how the damn thing works People not taking the time to learn is not a reason to throw an entire building block of the web out. (Yes, I realize there are a lot of people who know CSS and still choose CSS-in-JS, but I'm specifically referencing the point re: not learning CSS.)

I didn’t say I did not spend time, I said - could not. Same applies for most people in the team. I think we had coupe folks who were spending a lot of their time explaining CSS. My theory is that CSS was something that was treated as a task. Make a lot of client/server side development and then make these freaking lines align perfectly. So, most of time engineers were avoiding styles, applying them was the most tedio…

I agree with you re: the task comment, there is a difference between JavaScript developers and Front End UI developers. It's almost like the full stack discussion but just in the front end ecosystem.

Re: Why I Write CSS in JavaScript

#145

Story of my life as a front end developer... you can invent an abstraction to make life easier and simultaneously increase code size and complexity more than 10 fold. Easy is often an anti-thesis of simple. Basic front end code isn't that challenging, but it does take some actual practice (not half-ass practice followed by a million poorly considered short-cuts).

What about non-basic front end code?

Re: Why I Write CSS in JavaScript

#146

How do you handle advanced CSS Level 3/4 selectors, CSS grid, and media queries?

Yeah or pseudo elements / hover / focus etc?

People often confuse the two, but CSS-in-JS is a distinct concept from "inline styles" (which can make pseudo selectors more challenging).

Almost all CSS-in-JS solutions (including styled-components mentioned in the article) still support pseudo selectors, media queries, etc.

Re: Why I Write CSS in JavaScript

#148

I write CSS in CSS and my JavaScript in JavaScript because at some point abstractions pile up into this massive cognitive burden for anyone adopting your code, especially when they didn't follow the exact same path as you technology-wise or if they're newcomers. I want my work to be pick-up-and-play, not RTFM x 20 abstractions and tools.

Even if there was more cognitive burden, it's insignificant compared to the drastically reduced amount of context switches the developer has to deal with.

Re: Why I Write CSS in JavaScript

#149

Earlier quoted context omitted.

> and has a very wierd concept of how objects work in JS. What is so weird about it? I personally find Vue vastly more approachable than React is, especially once you have to start writing all the plumbing to get all the libraries you need to go along with it to write a real world app. > ] It's a templating system with its own rules and mini-DSLs that ends up being compiled into JS. Vue has the option to use Webpack…

> What is so weird about it? I go a bit in depth here: https://news.ycombinator.com/item?id=17471199 > Vue has the option to use Webpack to compile html compliant templates to JS functions just like JSX Vue's templates are not HTML-compliant. They are just that: templates. That get compiled to JS anyway. > JSX (which BTW is not JavaScript and not HTML compliant and is also a separate concept that needs to be learned…

I thought one of the beauty of vue template is 'It is not complete set of JavaScript logics, only subset that just able to support proper html structure.'.

It means you can't abuse JavaScript everywhere, creating totally unreadable render function, nest array mapping in Ternary operator and reduce it to what the hell no one can read and destroy all the readabilities.

For me, for you, for everyone, if you using that syntax, then it is simply readable just like html.

Less powerful, but the management definitly worth more.

Re: Why I Write CSS in JavaScript

#150
post #47

We built a relatively large social media management platform, and for one of our major features (a streams page that shows social media activities from different sources), we put a lot of our css in JS including all the logic for stream sizing/resizing and page responsiveness. I can honestly say that this approach is terrible. It is a maintenance nightmare. Even the smallest changes require a ton of time. We're now r…

I am curious, what made it a maintenance nightmare?
Post reply on HN