The Best Way To Style Components In React | CSS Modules

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ธ.ค. 2024
  • In this video, I'm going to show you how to use CSS modules in React. CSS modules is a new feature in React which allows you to manage your CSS in modular fashion. This is a huge advantage over using conventional CSS files, because it makes your code more organized and manageable.
    If you're interested in learning more about CSS modules or React, then this is the video for you! I'll show you how to use CSS modules in React, and how it can help you write more organized and manageable code.

ความคิดเห็น • 17

  • @jaybarls
    @jaybarls 10 หลายเดือนก่อน +3

    This is a great explanation, cheers! I'd been considering all the options including CSS-in-JS, but I like the simplicity and local scoping that modules offer - feel like modules are my preferred approach (for now).

  • @TheOlolo123
    @TheOlolo123 11 หลายเดือนก่อน +11

    By the way, it's not necessary to use string interpolation, className={classes.example} is enough

  • @kristofs8893
    @kristofs8893 20 วันที่ผ่านมา

    I have a tip for you. If you use bracket notation you can still use dashes instead of camelCasing your CSS classes. Much more Vanilla CSS like in my opinion of course. :)

  • @laraleon8033
    @laraleon8033 10 หลายเดือนก่อน +2

    Isn't this the same as having another class in the .css for the other button?

    • @morteza7298
      @morteza7298 8 หลายเดือนก่อน +1

      yes it is, but having all your classes in one css file doesn't scope very well, your bundle size increases and in larger projects it may causes problems like having duplicate or classes with the same name and having to use !important and so on, but by using modules, you can have a class named for example "paper" in all your modules

  • @hello-ff8hh
    @hello-ff8hh 8 หลายเดือนก่อน +2

    love the background music

  • @RajeshTechForge
    @RajeshTechForge 7 หลายเดือนก่อน

    Thanks a lot for this video, as a React beginner it's a headache for me 😇

  • @TheOlolo123
    @TheOlolo123 11 หลายเดือนก่อน

    Have you tried use css modules with scss?

  • @yjefecustom
    @yjefecustom ปีที่แล้ว

    What's the difference between this and just using CSS id?

    • @ashhalidrees7525
      @ashhalidrees7525 6 หลายเดือนก่อน

      if u simply use the css id, u have to name the className of that specific react component same as that as u use in the css file, either way depends on u, but this one is convenient as
      u simple need the refernce to that module and write the class name defined in the css module

  • @pyroghost11
    @pyroghost11 3 หลายเดือนก่อน

    you don't need string interpoolation for one class

  • @szeredaiakos
    @szeredaiakos ปีที่แล้ว

    Before frontend frameworks I was a slicer. I witnessed the rise and death of IE6.... Never really had an issue with classnames clashing. But you do explain the audience where to click so .. yes. Styled components are cool. Rather have that thn some junior screwing up an entire app :).

    • @JBereza
      @JBereza 9 หลายเดือนก่อน +1

      How many people worked on that project? Also was all code in that page yours or did you used some 3rd party stuff too?

    • @szeredaiakos
      @szeredaiakos 9 หลายเดือนก่อน +1

      @JBereza mostly me, occasionally 3 of us. We used prefixing, which was intuitive enough to pick it up in a glance.
      And yes, we also used copy-paste stuff occasionally.
      Later, on larger projects, we did what now scss nesting compiles down to.

  • @Dadaadad268
    @Dadaadad268 9 หลายเดือนก่อน

    CSS Modules is new ?

  • @gerardotopete9711
    @gerardotopete9711 8 หลายเดือนก่อน

    Styling components with JSX syntax is really annoying. That's the only thing I dont like about React so far... the styling.

  • @mikewilliams6732
    @mikewilliams6732 9 หลายเดือนก่อน +2

    Music is too annoying...