r/programming • • Feb 18 '19

Why I Write CSS in JavaScript

https://mxstbr.com/thoughts/css-in-js/
0 Upvotes

10 comments sorted by

View all comments

3

u/cbrantley Feb 18 '19

We just had a recent dust up about this at my company. There was a solid styled-components camp and a solid traditional style sheet camp.

After listening to all the arguments we determined there is room for both. When a component requires specific styling to work properly (modals, for example) we put the styles in the component itself.

For general styling and theming we use a more traditional setup with SASS.

This gives us a nice separation of concerns between “functional” and “presentational” styling. And it means our designers can change the look and feel without breaking components and our engineers can update components without needing to dig through the SASS.

2

u/Slak44 Feb 18 '19

This gives us a nice separation of concerns between “functional” and “presentational” styling

This makes a lot of sense. CSS changed from "make the text big and red", to "control the page's layout". HTML was never enough for layout (that line of thinking gave us the nightmare that are table-based layouts).

All the color: red and the text-align: center are just fluff. But all the display: flex and the width: 50% are critical code that allows the website to make sense.

1

u/cbrantley Feb 18 '19

Bingo. Nailed it.