青いやつの進捗日記。

メモとしてべんきょうのしんちょくをかいていきます。あとで自分が検索しやすいもん

Reactでstyled-componentなプロジェクトに、reset.cssを導入する

最近はじめてstyled componentでCSSを書いています。

で、reset.cssを入れようと思ったのですが、もうそもそもどう入れるのかわからず。

qiita.com

を参考にやりました。


入れたresetは

github.com

こちら。このパッケージをnpmやyarnでインストールして、

_app.tsx

import { createGlobalStyle } from 'styled-components'
import reset from 'styled-reset'

const GlobalStyle = createGlobalStyle`
  ${reset}
`

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <GlobalStyle />
    </>
  )
}

でいけます。参考にしたQiitaではinjectGlobalで入れてますが、

qiita.com

styled-component v4 からcreateGlobalStyleが出来たので、こちらのほうが良さそうなのでこれで入れました。