className이 달라서 생기는 경고,
첫 페이지는 SSR로 작동하며 이후 CSR로 화면을 렌더링하게 되는데, 이때 서버에서 받은 해시+클래스명과 이후 클라이언트에서 작동하는 해시+클래스 명이 달라지면서 스타일을 불러올수 없는 문제가 발생한다.
해결 방법
1. 바벨 플러그인 설치
npm i babel-plugin-styled-components
2. .babelrc 파일 생성 후 작성
{
"presets": ["next/babel"],
"plugins": ["babel-plugin-styled-components"]
}
출처
[NextJS] styled-components 적용시 Prop `className` did not match. 해결 방법
prop ‘classname’ did not match 해결 방법
donis-note.medium.com
Styled-components # nextjs에서 className 오류
Warning : Props 'className' did not match next로 styled-components로 스타일 적용하고, 개발 서버를 띄워서 확인해보면 첫 페이지 로딩은 문제없이 잘 작동하고, 새로고침 이후 Warning : Props 'classNa
velog.io
'Development > React.js' 카테고리의 다른 글
리엑트 폰트 버그 (0) | 2022.05.15 |
---|---|
next - font를 글로벌 처리할 때 문제점 (0) | 2022.05.15 |
next - Head 컴포넌트 (0) | 2022.05.15 |
next - _app.js (0) | 2022.05.15 |
리엑트에서 moment.js 사용하기 (0) | 2022.05.14 |