CSS in JS: My favorite

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 42

  • @maciekdzikdrums
    @maciekdzikdrums 3 роки тому

    Good Job Harry ;) Love the history of CSS component to it !!

  • @adamtak3128
    @adamtak3128 5 років тому +3

    How would you organize your code when using the styled components approach? I found my react file got pretty large pretty quickly and it was annoying as hell to have to scroll up and down across the file. I also couldn't really think of a good folder structure to organize the code/have reusable styles. Hopefully u can point me to some good references.

    • @AdrianGonzalezBlogs
      @AdrianGonzalezBlogs 5 років тому

      I think the answer to this problem is just breaking each component into smaller and smaller components. I had exactly this same issue when adding styled components. This made me realize how much I could break my components into smaller ones.

    • @JashwantSinghChaudhary
      @JashwantSinghChaudhary 3 роки тому +1

      Create directories for components. And put style in separate file. e.g. If you had header.jsx earlier then you would create a directory header with header.jsx code in index.jsx and styles in style.jsx. And then you can import styles in header.jsx from style.jsx. This way, you would not have to change the header.jsx import in other files as index.jsx can be mported by directory name only.
      You can refer this boilerplate www.reactboilerplate.com/

  • @titogoda
    @titogoda 5 років тому +2

    I love the way you make videos and I learn a lot from you.
    Thanks Harry :)

    • @hswolff
      @hswolff  5 років тому

      Yay! So glad to hear!

  • @steve-g-
    @steve-g- 3 роки тому

    Excellent video - thanks! Since styled-components has a css prop now as well is there any major difference between it and emotion?

  • @engage-project
    @engage-project 4 роки тому +1

    Harry, if you haven't already, check out TailwindCSS. Different paradigm, and it has some serious benefits.

    • @ethanliu4012
      @ethanliu4012 4 роки тому +1

      Also check twin.macro , merged TailwindCSS into styled components or emotion , get benefit of both ,and more flexibility if you do not want to go 'all in' to tailwind .

  • @stefanbogdanovic590
    @stefanbogdanovic590 5 років тому +7

    If I am working with styled components, I like to write styled in separate files, so I can focus on jsx more, some times it gets messy when you mix js jsx html css all in same file. I suggest that Should write styled components separately. Nicee video broo keep up the good work.

    • @getmaxeddd
      @getmaxeddd 5 років тому +5

      I totally disagree. What is the point ? that's just extra work - importing from another file, also extra decision makings. What if your component file has only 1 or 2 styled components ? Do you really enjoy ALWAYS creating 2 files - index and style ? If so - you also have to always create folder for them. And at some point you'll have some style files that will have shared components -- you'll have 3 different Containers and Buttons in the same style file and you'll have to think how to name them. And you'll end up with BEM style prefixing. Why ? Nicely put your styled components below your jsx and that's it :)

    • @hswolff
      @hswolff  5 років тому +4

      Yep! I def think that’s a good strategy too! I tend to do that when my styles get very large. In general if a file gets longer than 600 lines that’s when I start to think about ways to make it smaller.

    • @stefanbogdanovic590
      @stefanbogdanovic590 5 років тому +1

      @@hswolff That's why I tend to make React work like Angular everything Should be in separate files. And thats soo nice, everytime you switch from html to js you are not thinking about writing html and soo. BTW I tried all of them and I know what I am talking. Have a nice Day Harry.

  • @nickfausti6194
    @nickfausti6194 3 роки тому

    Fantastic explanation! Thank you.

  • @theoligarchist1503
    @theoligarchist1503 4 роки тому

    great video.
    am planning to use CSS in rust stdweb, thats how i got to this video.
    very few people are doing this.

  • @nosnart9453
    @nosnart9453 5 років тому

    Can you make a video about styled-system or rebass?

    • @hswolff
      @hswolff  5 років тому

      Thank you for the great suggestions! Added it to my list!

    • @moshemo613
      @moshemo613 5 років тому

      +1 for a series of videos on styled-system and rebass

  • @moshemo613
    @moshemo613 5 років тому

    If I am only interested in making Styled Compoments in React, is there any advantage of Emotion over Styled Components? I personally don't have a need for their inline css function. Is there anything else that emotion can do that styled-components can't do?

    • @hswolff
      @hswolff  5 років тому

      Yeah Emotion also supports the css prop (emotion.sh/docs/css-prop), which styled component doesn't support at all.

  • @twiggeh3577
    @twiggeh3577 5 років тому +1

    Hellu, very cool Video :)
    I wanted to ask how you got Emotion to work without needing
    /** @jsx jsx */ and
    import { css , **jsx** } from '@emotion/core'
    Whenever i try to do it like you showed it, it doesn't work :(

    • @hswolff
      @hswolff  5 років тому +2

      You need to use the babel plugin! Note: it will not work with create-react-app!
      emotion.sh/docs/@emotion/babel-preset-css-prop

    • @twiggeh3577
      @twiggeh3577 5 років тому

      @@hswolff UA-cam didn't give me a notification that you replied RIP
      Oh yeah I used create-react-app . I guess they lock out any customization for compatibility reasons.
      Thanks for the reply :)

  • @DanielRios549
    @DanielRios549 3 роки тому +2

    The cons of applying the styles using JS is the most problem about CSS in JS, I prefer using SCSS modules in place of all theses CSS in JS solutions you show in the video, but, Linaria is isteresting, tall he others have this problem, CSS should not be in JS files, where you write it doesn't matter, but in the build, it should be in the CSS files.

  • @ManasTunga
    @ManasTunga 5 років тому

    Nice video Harry.

    • @hswolff
      @hswolff  5 років тому +1

      Thank you!

  • @kimduer6194
    @kimduer6194 5 років тому

    Super useful! Thank you!

    • @hswolff
      @hswolff  5 років тому

      You are welcome!!

  • @adnanrruka5152
    @adnanrruka5152 4 роки тому

    WOW!

  • @maymumk3618
    @maymumk3618 5 років тому

    Very good video harry!! Please keep up this great job 👌🏼👌🏼 i hope that you will cover styled-system and point the goal to use it other than emotions. Thx again

    • @hswolff
      @hswolff  5 років тому

      Ooo styled system is a good one too. That whole world is so interesting to me.

  • @ropewalkingelephant
    @ropewalkingelephant 5 років тому

    Take a look at theme-ui

    • @hswolff
      @hswolff  5 років тому +1

      Yeaaaah theme-ui is verrrry coool.

    • @moshemo613
      @moshemo613 5 років тому

      @@hswolff What can theme-ui do that styled-system and rebass can't do?

  • @MrJailbreakdude
    @MrJailbreakdude 5 років тому +1

    I personally prefer the Material-UI styling solution. Passing common values for color , etc through context and being able to reference them in any descendant components in the makeStyles function. Although the CSS-in-JS library that Facebook showed off at React Conf looks amazing and I'll definitely switch to that when they release it to the open source community

    • @AdrianGonzalezBlogs
      @AdrianGonzalezBlogs 5 років тому

      Yeah I saw that and can't wait for it to be released.

    • @hswolff
      @hswolff  5 років тому

      I think emotion provides that through their theme support too!

  • @Rssks
    @Rssks 5 років тому

    None of these solutions satisfies my vision of web component notation. Your video is good doe, don't get me wrong :)

    • @hswolff
      @hswolff  5 років тому

      haha i'll take it, thanks!

  • @jayasurian123
    @jayasurian123 5 років тому +2

    I would prefer css modules over these techniques.
    The html part would looks much cleaner i dislike seeing all these styles in the js code.

    • @hswolff
      @hswolff  5 років тому

      Fair enough! Gotta do what helps you the most!

  • @angladephil
    @angladephil 2 роки тому

    Definitly : never. Js is dedicated to logic not layout or design. it's heretic to mix the two of them, especially in a team dev.