Soy nuevo cuando se trata de React. He estado tratando de implementar el componente SimpleBottomNavigation pero recibo un error que dice
"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"Ya verifiqué en línea, pero ninguna de las respuestas dadas para problemas similares me ayudó. Intenté desinstalar e instalar todo nuevamente, verifiqué si la reacción y la reacción son las mismas, y si hay piezas de materiales necesarias.
¿Alguien podría ayudarme con eso?
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;y
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> ); }Hay dos paquetes.json... ¿es posible?
paquete.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" ] } }y
{ "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" } }El encabezado funciona correctamente, justo cuando agrego SimpleBottomNavigation en app.js, aparece una pantalla blanca.
¡Resuelto! Resultó que acabo de instalar los paquetes de @mui en otra carpeta... Dios mío, me tomó un tiempo descubrirlo...
Pero muchas gracias por intentar ayudar! :)