Reactgo: Styled Components

Created on 9 Feb 2017  Β·  8Comments  Β·  Source: reactGo/reactGo

image
ReactGo is now Homo neanderthalensis, and ReactGo should be Homo sapiens

Most helpful comment

I think we do have to consider revisiting how we handle our css in reactGo. It's been bothering me for a while.

Reason:

  • We use a couple of different libraries/tools that seem to share similar responsibilities

    • css-modules (to eliminate class name conflicts and allow you to write locally scoped css). I think this removes the need for BEM. πŸ‘

    • postcss



      • postcss-imports -> allow you to import files


      • postcss-cssnext





        • writing future css



        • declaring vars. Prior to this we could compose classNames from css modules for code-re-use. And after that we had a postcss-simple-vars dependency which handled this.



        • i personally haven't been using the newer syntax that much, and am wondering whether people find much value in it. It might just be a lack of familiarity.






Before we introduce styled-components πŸ’… (if we decide to), I would like to have a think/understanding of what each tool's responsibility is. Im just conscious of adding new tools and increasing the number of dependencies we have to support.

All 8 comments

LOL @ZeroCho .

Do you mean https://github.com/styled-components/styled-components? I went for a meetup awhile ago and was fascinated. However, I'm not sure whether it works well in server-side rendering.

@choonkending I am using it for ssr, and it's working fine. There were some issues with the Babel plugin, but if might be sorted now. Could be better to wait for v2 for more stable ssr and ++performance. Maybe @mxstbr could provide some info on current ssr status.

Also, see

Note: That image is to be taken with a grain of salt, neither of the creators of styled-components made it and it's not very… logical. πŸ˜‰

I use styled-components with SSR in production at https://daybook.co (that's based on Next.js) and it's working perfectly fine. The Babel plugin is still in beta while we're figuring out the kinks, but one doesn't need to use it for SSR with v1!

Thanks for that @mxstbr!

I _have_ been slowly transitioning to making layout or style components with css modules in other projects, and styled-components feels like logical transition for me.

(I really liked styled-components-magic-explained and react-children-deepdive btw! )

I think we do have to consider revisiting how we handle our css in reactGo. It's been bothering me for a while.

Reason:

  • We use a couple of different libraries/tools that seem to share similar responsibilities

    • css-modules (to eliminate class name conflicts and allow you to write locally scoped css). I think this removes the need for BEM. πŸ‘

    • postcss



      • postcss-imports -> allow you to import files


      • postcss-cssnext





        • writing future css



        • declaring vars. Prior to this we could compose classNames from css modules for code-re-use. And after that we had a postcss-simple-vars dependency which handled this.



        • i personally haven't been using the newer syntax that much, and am wondering whether people find much value in it. It might just be a lack of familiarity.






Before we introduce styled-components πŸ’… (if we decide to), I would like to have a think/understanding of what each tool's responsibility is. Im just conscious of adding new tools and increasing the number of dependencies we have to support.

I'm currently using styled-components on my personal "reactGo" (created on top of dvajs with SSR). Works pretty well and fits perfectly in this project. I'm just using css loaders for importing third-party css.
@mxstbr Thank you very much for that awesome project.

I have been trying out styled components as a spike for reactGo.

Pros:

  • πŸ‘ Able to create style rules dynamically. You can derive them from props in Javascript. This will be really handy if you wish to do transitions or animations.
  • πŸ‘ Configuration is abstracted away from us. We do not have to worry about webpack configurations for styled components.
  • πŸ‘ Encapsulated styling. No conflicts for className.

Cons:

  • πŸ‘Ž Coupled to React.

    • πŸ€” This is not really a huge disadvantage, given that reactGo has "react" in its name. However, it is good to keep in mind that your styling will have to be ported if your switch from React.

  • πŸ‘Ž Additional transformations for css will not be available to your styled components (if you have postcss)

    • πŸ€” Styled components have styles automatically prefixed. Any other transformation can arguably be performed within JS (which to me is a πŸ‘ because we don't need to delegate that transformation to another build tool.)

I am pretty sold on styled-components. Here is what I have done so far https://github.com/reactGo/reactGo/compare/master...choonkending:styled-components

I will slowly port the components across and see how we go from there.

πŸ‘Œ Let me know if you have any questions!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jrodl3r picture jrodl3r  Β·  6Comments

jrodl3r picture jrodl3r  Β·  9Comments

thientran1707 picture thientran1707  Β·  5Comments

newasmod picture newasmod  Β·  4Comments

gsccheng picture gsccheng  Β·  6Comments