6. Global Style & Theme
Reset CSS
npm i styled-reset<App/> 내부 최상단에 <Reset/>을 넣어주면 기본적으로 적용되는 margin 등의 스타일이 사라짐
Global Style
아래의 설정들을 전역스타일로 지정해주자
box-sizing을 border box로 바꾸기
1rem을 16px이 아니라 10px로 바꾸기
font-size는 16px을 1rem으로
한국어 keep-all 설정
createGlobalStyle로 컴포넌트를 만들어 <Reset/> 처럼 적용
import { createGlobalStyle } from 'styled-components';
const GlobalStyle = createGlobalStyle`
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
html {
font-size: 62.5%;
}
body {
font-size: 1.6rem;
}
:lang(ko) {
h1, h2, h3 {
word-break: keep-all;
}
}
`;
export default GlobalStyle;Theme
컴포넌트를 <ThemeProvider/>로 감싸면 내부에서 theme을 사용할 수 있음
<ThemeProvider/>는 context API를 이용하여 하위의 모든 컴포넌트들이 props.theme을 사용할 수 있게 해줌
theme props를 함수로도 넘길 수 있음
Last updated