Next.js + styled-components - 스타일이 적용되지 않는 에러

Yoon_Jung·2022년 4월 5일
0

에러모음

목록 보기
2/2
post-thumbnail

220405 스타일이 적용되기 전에 렌더가 되어버리는 문제

프로젝트 루트폴더에 아래와 같이 작성하여 추가하니 해결됨.

styled-components는 동적으로 className을 생성하는데 Next.js는 Pre Rendering을 지원하기 때문에 이후에 서버와 클라이언트의 className이 달라지면서 생기는 문제.

해당 플러그인은 서버와 클라이언트의 클래스명을 일치시켜줌.

npm i --save-dev babel-plugin-styled-components
// .babelrc
{
  "presets": ["next/babel"],
  "plugins": [
    [
      "babel-plugin-styled-components",
      { "fileName": true, "displayName": true, "pure": true }
    ]
  ]
}

https://velog.io/@hwang-eunji/Styled-components-nextjs%EC%97%90%EC%84%9C-className-%EC%98%A4%EB%A5%98

profile
https://codekyz.tistory.com/

0개의 댓글