'Invalid hook calls - react - material-ui
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>
);
}
Solution 1:[1]
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! :)
Solution 2:[2]
There two package.json... is it possbible?
package.json:
{
"name": "react-webite",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
"@testing-library/user-event": "^13.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.2.1",
"react-scripts": "5.0.0",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
and
{
"dependencies": {
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
"@material-ui/core": "^4.12.3",
"@mui/icons-material": "^5.5.1",
"@mui/material": "^5.5.2",
"axios": "^0.26.1",
"react-router-dom": "^6.2.2"
}
}
Header works properly, just when I add SimpleBottomNavigation in the app.js, a white screen appears.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user15374677 |
| Solution 2 | user15374677 |
