简体   繁体   English

当我尝试运行我的 React 应用程序时,我收到错误消息:“Invalid hook call”。 不明白为什么

[英]I get the Error message: “Invalid hook call” when I try to run my React app. Can't understand why

I get the error message: Invalid hook call. Hooks can only be called inside of the body of a function component我收到错误消息: Invalid hook call. Hooks can only be called inside of the body of a function component Invalid hook call. Hooks can only be called inside of the body of a function component when I try to run my react app.当我尝试运行我的 react 应用程序时Invalid hook call. Hooks can only be called inside of the body of a function component

 import React from "react"; import BarChart from "../components/BarChart"; import LineChart from "../components/LineChart"; import Navbar from "../components/Navbar"; import { makeStyles } from "@material-ui/core/styles"; const useStyles = makeStyles({ row: { display: "flex", flexDirection: "row" } }); const Index = () => { const classes = useStyles(); return ( <div> <Navbar /> <div className={classes.row}> <BarChart /> <LineChart /> </div> </div> ); }; export default Index;

It fails in line 16 ( const classes = useStyles(); ).它在第 16 行失败( const classes = useStyles(); )。

The Navbar, BarChart and LinChart components is just components that I have created and it doesn't seem like the code breaks in these components. Navbar、BarChart 和 LinChart 组件只是我创建的组件,这些组件中的代码似乎没有中断。 I'm able to run my code without any error messages if iI remove line 16.如果我删除第 16 行,我可以运行我的代码而不会出现任何错误消息。

Any ideas what might help?有什么想法可能有帮助吗?

I tried makeStyles locally and it worked perfectly fine.我在本地尝试了 makeStyles,它工作得非常好。 Kindly check your dependencies and update them to latest then try again.请检查您的依赖项并将它们更新到最新版本,然后重试。 I'm currently having: "react": "^16.8.2", "react-dom": "^16.8.2", "@material-ui/core": "^4.9.12"我目前有: "react": "^16.8.2", "react-dom": "^16.8.2", "@material-ui/core": "^4.9.12"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无效的钩子调用反应钩子,使用 react-table 尝试显示一些模拟 json,我不明白出了什么问题 - Invalid hook call react hook, Using react-table to try and display some mock json and I don't understand what is wrong 当重新加载发生时,我得到 Invalid hook call react 错误 - When reload happens i get Invalid hook call react error React 路由器的 useLocation 抛出一个无效的钩子使用错误,我不明白为什么 - React router's useLocation is throwing an invalid hook use error and I don't understand why react 说 Error: Invalid hook call when I try to use material makestyles - react says Error: Invalid hook call when I try to use material makestyles React App:为什么当我尝试运行 npm start 脚本时出现错误? - React App: Why I get an error when I try to run npm start script? 每当我尝试在我的 react/redux 应用程序中使用 getState() 方法时,我都会收到此错误。 getState() 不是 function 的原因是什么? - I get this error whenevever I try using getState() method in my react/redux app. What is the reason for getState() is not a function? 为什么我在 React 中收到“无效的 Hook Call”错误? - Why am I receiving 'Invalid Hook Call' error in React? 为什么我在 function 内部调用时会收到“错误:无效的挂钩调用”? - Why do I get 'Error: Invalid hook call' when I am calling inside a function? 错误:无效的挂钩调用。 但不明白在哪里。 反应 JS - Error: Invalid hook call. But can't understand where. React JS 当我在我的应用程序中使用材料设计引导程序组件时,在 React 中出现无效的钩子调用错误 - Getting invalid hook call error in React when I used materidal design bootstrap component in my application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM