'Getting ReferenceError: window is not defined in react, Next
I am developing a website in React. But I am getting ReferenceError: window is not defined in my _document.js
My Code as mention below:
import Document, { Html, Head, Main, NextScript } from 'next/document';
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx);
return { ...initialProps };
}
render() {
return (
<Html lang='en'>
<Head>
<link rel='icon' type='image/png' href='/images/favicon.png'></link>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
}
}
export default MyDocument;
I am getting the error in below mentioned line
const initialProps = await Document.getInitialProps(ctx)
Anyone can tell me why I am getting this issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
