Sitemap
Daniel Cavalcante

Daniel Cavalcante

Styling React

2 min readJul 19, 2018

When I started learning React about a year ago, its official documentation had an example that used CSS-in-JS which made me squirm a lot more than JSX at first sight. Despite the feel that regular CSS would be better suited for my (how very original) todo app, I decided to play along and see if it would make more sense later on.

Spoiler alert: it didn’t. After I finished the basics and started adding new features it was becoming even harder to manage. It prompted me to go back and check the docs again to understand why would they advocate such technique, but couldn’t find it anymore. It even claims that plain old CSS is better for performance.

Get Daniel Cavalcante’s stories in your inbox

Join Medium for free to get updates from this writer.

Before replacing the styling method of my app I decided to unearth what happened with the tutorial I had seen; also if there was any consensus along the React community about it. Googling about it shows that people are very divided about how effective CSS-in-JS really is. Some developers praise its versatility, while others are skeptical of the benefits.

Dan Abramov to the rescue

Scrolling through my Twitter timeline this post caught my attention:

So I decided to ask Dan why they replaced inline styles with pure CSS, claiming it felt like I was digging up remains of war won by the latter. He started by pointing out the confusion about what “inline style” means, since many CSS-in-JS implementations don’t actually use it. And that the “war” metaphor was inappropriate, since there aren’t only two but five or more techniques and neither have really “won” because each has its pros and cons.

He explained that “the main reason React docs distance themselves from CSS-in-JS is not because it’s objectively bad (some approaches are bad, some are pretty good) but because the community mistakingly associates CSS-in-JS with React. And we don’t want to be arbiters in that debate. So we document the least controversial option.” Also the reason that they removed the example I saw was because (just like I did) people used to see it as an endorsement.

Now I’m compiling a list of use cases where it makes sense to use CSS-in-JS (like this), but I’ll tell you upfront from my own experience that ordinary styles for a regular todo app isn’t one of them.

--

--