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

CSS in JS Pros & Cons

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Avatar for Jesse Jesse
September 05, 2019

CSS in JS Pros & Cons

This talk starts from discussing some issues came alone with how CSS was originally designed and how developers tried to solve it. And later on focus on explaining the uprising CSS in JS solutions.

Avatar for Jesse

Jesse

September 05, 2019

Other Decks in Programming

Transcript

  1. Vanilla CSS • simple and intuitive: developers want a more

    versatile way to define styles • Originally designed to be global: class naming become a problem when application's scale grows
  2. Needs & Solutions • avoid naming conflict: BEM naming convention

    • syntax sugars: preprocessors SASS LESS • nested style • import other stylesheet • variable • vendor prefix
  3. About preprocessors • Pros: • Cons: • has been used

    for a long time, very well developed • postcss: modulize each feature of the preprocessor, widely used as webpack loaders • still has naming conflict
  4. CSS in JS • Define styles • Apply styles to

    components • Avoid naming conflict
  5. The difference between stylis and JSS stylis's api takes an

    unique selector and supports nested rules. JSS works the other way around
  6. Styled components? • Why section has to be specified •

    .child can possibly to be overwritten • Is it necessary to create an extra component only for styles • Hook api?
  7. Stylesheets is dynamic • Utilize React.context to provide themes •

    Able to change styles based on the state of components • unique class names is static during runtime, they should be settled during bundling process
  8. Knowing what's your needs first • static pages/app scale is

    relatively small: vanilla css • hate naming convention: css-module(css-loader) • comprehensive capability(come along with complexity): emotion / styled-components / react material-ui
  9. Another approach • Originally designed to be global: lit-element/shadow DOM:

    styles defined inside the component is already scoped.