Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Modules & React

CSS Modules & React

CSS improved a lot in the last years but for many, it's still one of the hardest parts to handle while developing big web applications. Pre-processed languages like Sass and Less added many new features but we still have to rely on methodologies such as BEM and OOCSS to avoid name collisions.

In ReactJS many people tried to solve these issues using the style attribute or by developing libraries like Radium. Although these approaches fix some of the problems they bring new challenges on their own.

CSS Modules give you the best of both words. Write CSS code using all the tools you love and forget about name collisions.

In this talk, I will explain what CSS Modules are, why they are so good and how you can use them in your project.

Giorgio Polvara

July 24, 2016
Tweet

More Decks by Giorgio Polvara

Other Decks in Programming

Transcript

  1. CSS

  2. CSS

  3. CSS

  4. CSS

  5. $bg-cl: blue; .one { background-color: $bg-cl; } :root { --bg-cl:

    blue; } .one { background-color: var(--bg-cl); } NO VARIABLES
  6. var styles = { label: { fontSize: '1.5rem' } }

    .label { font-size: 1.5rem; }
  7. var styles = { label: { fontSize: '1.5rem' } }

    render () { return ( <div /> ) }
  8. var styles = { label: { fontSize: '1.5rem' } }

    render () { return ( <div style={styles.label} /> ) }
  9. PERFORMANCE Click Me Click Me Click Me Click Me Click

    Me Click Me Click Me Click Me Click Me
  10. .label { font-size: 1.5rem; } import styles from './menu.css'; render

    () { return ( <div className={styles.label} /> ) } menu.css menu.js
  11. import styles from './menu.css'; render () { return ( <div

    className={styles.label} /> ) } <div class='menu_label_456cd' />
  12. .label { font-size: 1.5rem; } menu.css .label { color: #bada55;

    } hero.css .label { font-weight: bold; } form.css
  13. .label { font-size: 1.5rem; } menu.css .label { color: #bada55;

    } hero.css .label { font-weight: bold; } form.css .hero_label_123ab { color: #bada55; } .menu_label_456cd { font-size: 1.5rem; } .form_label_789ef { font-weight: bold; } bundle.css
  14. .className { color: green; background: red; } .otherClassName { composes:

    className; color: yellow; } .otherClassName { composes: className from "./style.css"; color: yellow; }
  15. .label { font-size: 1.5rem; } .label:hover { color: red; }

    .pointer + .label { cursor: pointer; }
  16. .label { font-size: 1.5rem; } .label:hover { color: red; }

    .pointer + .label { cursor: pointer; } .item { color: $brand; &:hover { color: invert($brand); } }
  17. .label { font-size: 1.5rem; } .label:hover { color: red; }

    .pointer + .label { cursor: pointer; } .item { color: $brand; &:hover { color: invert($brand); } } .pane { display: flex; }