Skip to content

Commit

Permalink
CSS-in-JS explanation
Browse files Browse the repository at this point in the history
Let the wars begin about CSS-in-JS!
  • Loading branch information
shannonbux committed Jan 8, 2018
1 parent 22c9b68 commit 23012dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/docs/glamor.md
Expand Up @@ -6,7 +6,11 @@ Let's create a page using
[Glamor](https://github.com/threepointone/glamor). It might be useful for you to explore [CSS Modules](/tutorial/part-two/) and [Styled Components](/styled-components.md) to see how Glamor compares as a styling method.

Glamor lets you write _real_ CSS inline in your components using the same Object
CSS syntax React supports for the `style` prop.
CSS syntax React supports for the `style` prop. Glamor is a variant on "CSS-in-JS"—which solves many of the problems with traditional CSS.

One of the most important problems they solve is selector name collisions. With traditional CSS, you have to be careful not to overwrite CSS selectors used elsewhere in a site because all CSS selectors live in the same global namespace. This unfortunate restriction can lead to elaborate (and often confusing) selector naming schemes.

With CSS-in-JS, you avoid all that as CSS selectors are scoped automatically to their component. Styles are tightly coupled with their components. This makes it very easy to know how to edit a component's CSS as there's never any confusion about how and where CSS is being used.

First, install the Gatsby plugin for Glamor.

Expand Down
6 changes: 5 additions & 1 deletion docs/docs/styled-components.md
Expand Up @@ -4,7 +4,11 @@ title: Styled Components

[Styled Components](https://www.styled-components.com/) is an example of using CSS-in-JS. It might be useful for you to explore [CSS Modules](/tutorial/part-two/) and [Glamor](/glamor.md) to see how Styled Components compares as a styling method.

Styled Components lets you use actual CSS syntax inside your components.
Styled Components lets you use actual CSS syntax inside your components. Like Glamor, Styled Components is a variant on "CSS-in-JS"—which solves many of the problems with traditional CSS.

One of the most important problems they solve is selector name collisions. With traditional CSS, you have to be careful not to overwrite CSS selectors used elsewhere in a site because all CSS selectors live in the same global namespace. This unfortunate restriction can lead to elaborate (and often confusing) selector naming schemes.

With CSS-in-JS, you avoid all that as CSS selectors are scoped automatically to their component. Styles are tightly coupled with their components. This makes it very easy to know how to edit a component's CSS as there's never any confusion about how and where CSS is being used.

First, we'll install the Gatsby plugin for Styled Components.

Expand Down

0 comments on commit 23012dc

Please sign in to comment.