CSS의 문제점 (React를 쓰면서)
https://styled-components.com/
npm insatll --save styled-components
상태가 바뀌거나 훅이 바뀌는 등의 이유로 컴포넌트는 리렌더링이 될텐데, 이 내부에 styled-components를 넣게 되면 이마저도 계속 새로 그려질 것이다.
따라서, 재사용성과 속도 측면에서 보았을 때 밖으로 빼는 게 좋다.
'&' 자기 자신을 의미한다. 나를 특정할 수 있다.
'& ~ &' Thing 주변에 Thing이 하나라도
'& + &' <a>
라는 태그 바로 옆의 <b>
태그를 의미한다.
https://emotion.sh/docs/introduction
npm i @emotion/styled @emotion/react
CRA를 사용하는 경우
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react'
css={{fontSize: 12}}
css={css`font-size: 12px`}
background
의 값을 배열로 넣으면, linear-gradient가 지원되는 브라우저에서는 배경색이 그라데이션으로, 지원되지 않는 브라우저에서는 red
로 나오게 되는 것이다. <div
css={{
background: [
'red',
'linear-gradient(#e66465, #9198e5)'
],
height: 100
}}
>
npm install sass