【发布时间】:2020-04-01 17:20:02
【问题描述】:
我创建了一个非常简单的 Next.js 项目,它只包含一个页面,index.js,看起来像:
import React, { useState } from 'react';
const MyComponent = () => {
const [instance, setInstance] = useState()
return (
<></>
);
};
const Home = () => <>
<MyComponent />
</>;
export default Home;
当我在开发模式下运行它时,没有错误,一切正常。
但是当我运行next build 时,我得到:
Error occurred prerendering page "/": Error: Minified React error #321; visit https://reactjs.org/docs/error-decoder.html?invariant=321 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
> Build error occurred
看起来钩子有问题,但我不明白我的实现有什么问题。如果我删除const [instance, setInstance] = useState()这一行,则构建成功。
我正在使用 next ^9.1.4,react ^16.12.0 和 react-dom ^16.12.0。
你能帮我解决这个问题吗? :)
【问题讨论】:
标签: reactjs react-hooks next.js