Next.js + styled-components - 스타일이 적용되지 않는 에러
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 }
]
]
}
Author And Source
이 문제에 관하여(Next.js + styled-components - 스타일이 적용되지 않는 에러), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@kyz0111/Next.js-styled-components-스타일이-적용되지-않는-에러저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)