【发布时间】:2021-12-09 04:08:37
【问题描述】:
为什么在这里发帖这么难,我在标题中输入的所有内容都不被接受,所以抱歉没有意义。
大家好!我遇到了这个错误
错误:无效的挂钩调用。钩子只能在函数组件的主体内部调用。这可能是由于以下原因之一:
- 您可能有不匹配的 React 版本和渲染器(例如 React DOM)
- 您可能违反了 Hooks 规则
- 您可能在同一个应用程序中拥有多个 React 副本 有关如何调试和解决此问题的提示,请参阅 https://reactjs.org/link/invalid-hook-call。
这似乎只发生在我导入 material-ui 之后。我很困惑。这是我的代码。
import {Container, AppBar, Typography, Grow, Grid} from '@material-ui/core'
import bandmate from './images/bandmate.jpeg'
const App = ()=> {
return (
<Container maxidth = 'lg'>
<AppBar position = 'static' color = 'inherit'>
<Typography varaint = "h2" align = 'center'>BandMate</Typography>
<img src= {bandmate} alt = 'bandmate' height= '60'/>
</AppBar>
</Container>
);
}
export default App;
我遇到的解决方案似乎引用了 webpack,我没有使用 webpack,所以我不确定该去哪里。我按照上面的链接并按照说明运行了这段代码,它返回 false,这意味着我有一个重复的反应问题
window.React1 = require('react');
// Add this in your component file
require('react-dom');
window.React2 = require('react');
console.log(window.React1 === window.React2);```
I've seen some people say to try npm link but I cant seem to get that to work either. I ran ```npm link ../myProjectName/client/node_modules/react``` Im not even sure if I am using npm link correctly, but I just get a ton of errors. All of the posts seem to point to this, but I either don't understand what I'm doing or its not the correct solution.
Thank you all in advance for your help, I have been struggling with this for 2 days now with no progress.
Also I'm not sure what is up with my formatting, I thought you open and close with ``` ``` but I guess not.
【问题讨论】:
标签: javascript reactjs material-ui