๋ณธ๋ฌธ์œผ๋กœ ๋ฐ”๋กœ๊ฐ€๊ธฐ

ํ…Œ๋งˆ ์ •์˜

//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

๋ฐ˜์‘ํ˜•