【发布时间】:2020-10-22 08:28:17
【问题描述】:
我有一个需要帮助的错误。每当我访问主页时,我的 Next.js 应用程序都会中断。我不断收到无法读取未定义的数据映射错误。浏览器一直将我指向我的 _document.js 文件,我似乎在这里找不到错误,因为这个应用程序到目前为止一直运行良好。我将在下面粘贴一些代码。
import Document, { Head, Main, NextScript } from 'next/document';
import { ServerStyleSheet } from 'styled-components';
export default class MyDocument extends Document {
static getInitialProps({ renderPage }) {
const sheet = new ServerStyleSheet();
const page = renderPage(App => props => sheet.collectStyles(<App {...props} />));
const styleTags = sheet.getStyleElement();
return { ...page, styleTags };
}
render() {
return (
<html>
<Head>{this.props.styleTags}</Head>
<body>
<Main />
<NextScript />
</body>
</html>
);
}
}
我的浏览器一直指向 const 页面变量。
【问题讨论】:
标签: javascript reactjs next.js styled-components