Open tmdqls2257 opened 2 years ago
$ window is not defined nextjs
즉, server-side에서 먼저 실행 되고, 그 후에 client-side에서 실행된다. window는 client-side에만 존재한다. 고로 React Component내에서 window를 사용하고 싶다면 componentDidMount내에 코드를 작성해야한다.
if (typeof window !== 'undefined') { require('the-lib'); }
어떤 에러인가요?
에러 핸들링 방법
즉, server-side에서 먼저 실행 되고, 그 후에 client-side에서 실행된다. window는 client-side에만 존재한다. 고로 React Component내에서 window를 사용하고 싶다면 componentDidMount내에 코드를 작성해야한다.
에러 핸들링을 위해 참고한 레퍼런스 링크