reactjs - NextJS (React) - 错误:无效的钩子调用 (useState)
问题描述
我正在使用 NextJS 进行服务器端渲染,并且我正在尝试在正在抛出的组件内使用 useState 钩子:
错误:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
我的代码:
import { useState } from 'react';
const Banner = ({ movies }) => {
const [movie, setMovie] = useState(movies);
return (
<header>
<h1> Banner </h1>
</header>
)
}
export default Banner;
目录树
/components/Banner.js
/pages
当我使用 useEffect() 时出现相同的错误:
从“反应”导入反应,{useEffect}
解决方案
推荐阅读
- c# - 从 64 位 c# WinForms 应用程序调用第三方 32 位 dll 时的事件处理
- python - 有没有办法配置 docker compose 在容器服务之间共享 python 包?
- c# - 如何从 Azure 应用服务连接字符串设置 ASP.Net Core exe.config 值
- javascript - 输入文本框显示结束字符串比从开始
- android - 我可以使用 RFCOMM 蓝牙协议在 iOS 设备和另一台设备之间共享数据吗?
- python - 使用 pandas 将描述符保存到 csv
- hyperledger-fabric - 链码事件负载 - Hyperledger Fabric SDK v1.4.1
- android - 谷歌地图方向api不适合我
- apache-camel - 如何在 Apache Camel 版本 2.23.1 的处理器交换对象中获取 RouteId?
- laravel - Laravel 邮件发送很慢