无效的挂钩呼叫 - react-材料-UI
在反应方面,我是新手。我一直在尝试实现简单的行动组件,但是我遇到了一个错误,说
"Uncaught 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
See https://reactjs.org/link/invalid-hook-call for tips about how"
我已经在网上检查了,但是类似问题的给定答案都没有帮助 - 我尝试卸载和安装所有内容,检查是否反应和重新进行了检查。 DOM是相同的,如果有必要的材料零件。
有人可以帮我吗?
import './App.css';
import Header from './components/Header';
import SimpleBottomNavigation from './components/MainNav';
function App() {
return (
<div className="App">
<Header />
<SimpleBottomNavigation />
</div>
);
}
export default App;
和
import * as React from 'react';
import Box from '@mui/material/Box';
import BottomNavigation from '@mui/material/BottomNavigation';
import BottomNavigationAction from '@mui/material/BottomNavigationAction';
import RestoreIcon from '@mui/icons-material/Restore';
import FavoriteIcon from '@mui/icons-material/Favorite';
import LocationOnIcon from '@mui/icons-material/LocationOn';
export default function SimpleBottomNavigation() {
const [value, setValue] = React.useState(0);
return (
<Box sx={{ width: 500 }}>
<BottomNavigation
showLabels
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
>
<BottomNavigationAction label="Recents" icon={<RestoreIcon />} />
<BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} />
<BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} />
</BottomNavigation>
</Box>
);
}
I am new when it comes to React. I've been trying to implement SimpleBottomNavigation component but I'm getting an error saying
"Uncaught 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
See https://reactjs.org/link/invalid-hook-call for tips about how"
I have already checked online but none of the given answers for the similar issues helped - I have tried uninstalling and installing everything again, checked if the react and reac-dom is the same, and if there are necessary materials parts.
Could anyone help me me with it?
import './App.css';
import Header from './components/Header';
import SimpleBottomNavigation from './components/MainNav';
function App() {
return (
<div className="App">
<Header />
<SimpleBottomNavigation />
</div>
);
}
export default App;
and
import * as React from 'react';
import Box from '@mui/material/Box';
import BottomNavigation from '@mui/material/BottomNavigation';
import BottomNavigationAction from '@mui/material/BottomNavigationAction';
import RestoreIcon from '@mui/icons-material/Restore';
import FavoriteIcon from '@mui/icons-material/Favorite';
import LocationOnIcon from '@mui/icons-material/LocationOn';
export default function SimpleBottomNavigation() {
const [value, setValue] = React.useState(0);
return (
<Box sx={{ width: 500 }}>
<BottomNavigation
showLabels
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
>
<BottomNavigationAction label="Recents" icon={<RestoreIcon />} />
<BottomNavigationAction label="Favorites" icon={<FavoriteIcon />} />
<BottomNavigationAction label="Nearby" icon={<LocationOnIcon />} />
</BottomNavigation>
</Box>
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有两个package.json...可能吗?
package.json:
并且
Header 工作正常,只是当我在 app.js 中添加 SimpleBottomNavigation 时,出现白屏。
There two package.json... is it possbible?
package.json:
and
Header works properly, just when I add SimpleBottomNavigation in the app.js, a white screen appears.
解决了!原来我只是在另一个文件夹中安装了 @mui 包...天哪,我花了一段时间才找到它..
但是非常感谢您的帮助! :)
Resolved! It turned out I just installed @mui packages in another folder... omg it took me a while to find it out..
But thanks a lot for trying to help! :)