
ํ ๋ง ์ ์
//styled.d.ts
import 'styled-components';
declare module 'styled-components' {
export interface DefaultTheme {
colors: {
'--color-gray': string;
'--color-gray800': string;
'--color-gray700': string;
};
}
}
//theme.ts
import { DefaultTheme } from 'styled-components';
export const theme: DefaultTheme = {
colors: {
'--color-gray': 'rgba(58,58,58,1)',
'--color-gray800': 'rgba(58,58,58,0.8)',
'--color-gray700': 'rgba(58,58,58,0.7)',
},
};
ํ ๋ง ์ฌ์ฉ
import { ThemeProvider } from 'styled-components';
function App() {
return (
<>
<ThemeProvider theme={theme}>
...
</ThemeProvider>
</>
);
}
const LogoContainer = styled.div`
color: ${(props) => props.theme.colors['--color-gray700']};
`
๊ธ๋ก๋ฒ ์คํ์ผ ์ ์ & ์ฌ์ฉ
//global-styles.ts
import { createGlobalStyle } from 'styled-components';
import { normalize } from 'styled-normalize';
export const GlobalStyle = createGlobalStyle`
${normalize}
html {
display: block;
}
strong{
font-weight: bold;
}
`;
styled-normalize
reset.css, normalized.css์ ์ญํ ์ ํ๋ ๊ฒ์ผ๋ก, ๋ธ๋ผ์ฐ์ ๊ฐ์ ์ฐจ์ด๋ฅผ ์ต๋ํ ์์ ๋ ์ฝ๋๋ฅผ ๋ฃ์ด์, ๋ธ๋ผ์ฐ์ ์์๋ค์ ์คํ์ผ์ด 0์ธ ์ํ์์ ๋์์ธ์ ๋ง๋ค์ด ๋๊ฐ๊ธฐ ์ํด ์๊ฒจ๋ ๊ฒ์ด๋ค.
function App() {
return (
<>
<GlobalStyle />
...
</>
);
}
Reference
1. npx create-react-app my-app --template typescript
2. https://velog.io/@kmlee95/React-Typescript-eslint-prettier%EC%84%A4%EC%A0%95
3. npm i --save-dev @types/styled-component
4. .eslicrc ์์ https://github.com/prettier/eslint-config-prettier/blob/main/CHANGELOG.md#version-800-2021-02-21
5. ์ ๋ฐ์ ์ธ ์
ํ
https://velog.io/@junghyeonsu/React-create-react-app-Typescript-%EC%B4%88%EA%B8%B0-%EC%84%B8%ED%8C%85-%EC%99%84%EB%B2%BD-%EC%A0%95%EB%A6%AC
6. ์คํ์ผ ์ปดํฌ๋ํธ๋ ํจ์ ์์ ์ ์ํ๋ฉด ์๋๋ค. https://medium.com/geekculture/you-may-see-this-warning-because-youve-called-styled-inside-another-component-styled-components-7766b4740b22
'๐ Front > โ๏ธ React JS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| React [๋ฆฌ๋ ๋๋ง ๊ณผ์ ] (0) | 2021.09.08 |
|---|---|
| [JSX]: JS์ JSX ํ์ฅ์๋ ๋ฌด์์ด ๋ค๋ฅผ๊น? (0) | 2021.09.07 |
| [React Hook ์๋ฆฌ์ฆ 3]: 10๊ฐ์ง Hook๋ค (useMemo, useRef ๋ฑ) (0) | 2021.08.03 |
| [React Hook ์๋ฆฌ์ฆ 2]: useEffect() (0) | 2021.07.22 |
| [React Hook ์๋ฆฌ์ฆ 1]: ์ฐ๋ ์ด์ , useState() (0) | 2021.07.20 |