The Best Way To Style Components In React | CSS Modules

Поделиться
HTML-код
  • Опубликовано: 11 июл 2023
  • 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.
  • НаукаНаука

Комментарии • 15

  • @jamaha2546
    @jamaha2546 3 месяца назад +1

    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).

  • @hello-ff8hh
    @hello-ff8hh Месяц назад +2

    love the background music

  • @RajeshTechForge
    @RajeshTechForge 17 дней назад

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

  • @TheOlolo123
    @TheOlolo123 4 месяца назад +2

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

  • @TheOlolo123
    @TheOlolo123 4 месяца назад

    Have you tried use css modules with scss?

  • @laraleon8033
    @laraleon8033 3 месяца назад +2

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

    • @morteza7298
      @morteza7298 2 месяца назад

      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

  • @yjefecustom
    @yjefecustom 5 месяцев назад

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

    • @ashhalidrees7525
      @ashhalidrees7525 9 дней назад

      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

  • @szeredaiakos
    @szeredaiakos 8 месяцев назад

    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 2 месяца назад +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 2 месяца назад +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 2 месяца назад

    CSS Modules is new ?

  • @mikewilliams6732
    @mikewilliams6732 3 месяца назад +1

    Music is too annoying...

  • @gerardotopete9711
    @gerardotopete9711 Месяц назад

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