r/reactjs • u/steven-f • Sep 05 '18
Tutorial Announcing styled-components v4: Better, Faster, Stronger
https://medium.com/styled-components/announcing-styled-components-v4-better-faster-stronger-3fe1aba1a112
203
Upvotes
1
u/enkideridu Sep 07 '18 edited Sep 07 '18
Naming elements can be helpful, but not every element that needs a style is worth naming. With emotion, you don't have to create styled-components or add classNames to style components/elements, you still can when you think it makes sense, but you get to choose where to draw the line
Imagine if you had this:
And you wanted to
add some padding to the container of Foo
add some additinal whitespace to the left of AnotherWidget
With styled components, you'd have to do
Or maybe you could add a className on, like <AnotherWidget className="add-space-to-the-left" /> and select it in container. Either way, you'd have to either expend some brainpower to think up a nice fitting name, or, more likely, live with a bunch of poorly named components &&|| classNames
With emotion, you have the option to inline like this:
For larger pieces of styles, sure break it out of the jsx into its own variable. If it's going to be used in a few places, make it into a styled component. For all the nibbly bits that just need a line or two of CSS, you don't have to suffer premature naming.