Styled components versus SASS (SCSS) or LESS

I came across a ReactJS Boilerplate, which had good representatives and was community oriented. The Styling section focuses on the CSS styling component, but he never stopped moving on to the usual CSS styling methodologies. Although it caught my attention to what distinguishes the Styled-Component CSS element and why it should be accepted.

My understanding of the stylized CSS component :

  1. Component-driven ideology. Your CSS is now also a component. - This is very cool!
  2. Download what you need and when you need, a little lazy CSS
  3. The supplier of themes, skins, modularity and dynamics - this can be achieved by other libraries
  4. Building the server side of your DOM component and its style.

My questions:

  1. Browsers are developed to parse CSS separately from Javascript parsing, why are we trying to move away from this and fit everything into Javascript?

  2. The Styled CSS component delivers its JavaScript library to the client side, which actually parses the styles at runtime and puts them inside the tag <style />when each component loads on demand. This means extra workload and logic, ultimately contributing to the execution cycles in the browser. Why is this needed?

    (By the above question, I mean that for each loaded component, the corresponding CSS is calculated, created and inserted into the head using a tag style/ several styles - a re-invention of CSS interpreters)

  3. <style /> head / ?

  4. ?

  5. /, Post-CSS & SCSS , , . ?

, , , .


, DOM, , CSS.

+22
3

CSS Javascript, Javascript?

Javascript HTML ( JSX), CSS (JSS ), , . .

: JSX , "HTML" ( ), , CSS-in-JS - , "CSS" ( ). , JSX CSS--JS.

Styled-component CSS javascript , <style />, . , .

. CSS-in-JSS - , CSS, . Node, SSR, style, , , CSS.

?

, React Redux, jQuery, , , .

, . , , ?

<style /> / ?

, .

. , . , , .

(), , .

+1

SCSS (SASS) , Styled-Components , .

, , Styled-Components :

Styled- -

  1. ; , .
  2. ,
  3. , CSS JSX ( )

  4. JavaScript

Styled- -

  1. -, , , "" .
  2. : , .

, .


SCSS/LESS , , , (IMHO). "", :

:

SCSS:

.icon{
  $size: '20px';
  width: $size;
  height: $size;
  margin-left: $size/2;
}

Styled-Components:

const Icon = styled.i(props => {
  const size = 20; // easier to use Number instead of String for calculations 
  return '
    width: ${size}px;
    height: ${size}px;
    margin-left: ${size/2}px;
'});

, Icon , , CSS- styleled- CSS:

const Header = styled.header'
   > ul{
     ...
   }

   li{
     ...
   }

   img{...}

   navigation{...}
'

HTML . , .

SASS, javascript, SASS.

, Styled-Components - , / , , (, , ),

+1

Google Reflow :

  • CSS CSS.

  • CSS- - , - - .

Styled-Components React.

, , / CSS . , , . , CSS , , - .

, , Styled Components/CSS-in-JS, .

, , " ", , , , , , , .

React/React-Bootstrap Code Sandbox, CSS, , CSS-. , React-Bootstrap , React-Bootstrap. , , Google.

CSS CSS-in-JS:

  • DOM. DOM - . , .

  • CSS CSS. , , . .

, , . , , , , , . .

-1

Source: https://habr.com/ru/post/1687492/


All Articles