# assuming you already have @emotion/react installed
$ yarn add @emotion/styled
기본 문법
css() 함수
css() 함수의 반환 결과로 해당 스타일을 적용하고 싶은 HTML 요소나 React 컴포넌트의 css라는 prop에 넘겨줌
인자를 객체형 또는 문자형으로 넘길 수 있는데, Emotion 공식문서에서는 가급적 스타일을 객체로 선언 권장
css() 함수 호출 생략하고 요소 혹은 컴포넌트 css prop에 바로 객체를 넘길 수 있음
TS 사용 시 type checking 을 통해 오타 방지
예시 (객체형 인자, 문자형 인자)
/** @jsxImportSource @emotion/react */
// JSX pragma : React의 jsx() 함수를 사용하지 말고, Emotion의 jsx() 함수를 대신 사용하라고 알려주기 위함
// css prop에 넘어간 스타일이 제대로 반영이 되지 않을테니 주의
import { css } from "@emotion/react";
function MyComponent() {
return (
<div
css={css({
backgroundColor: "yellow",
})}
>
노란색 영역
</div>
);
}
/** @jsxImportSource @emotion/react */
import { css } from "@emotion/react";
function MyComponent() {
return (
<div
css={css`
background-color: yellow;
`}
>
노란색 영역
</div>
);
}