As a newcomer to React, I decided to incorporate Material UI components into my project. After installing the components locally using npm install and importing them into my project, I encountered an error when trying to run start:
Error: Invalid hook call. Hooks can only be called inside of a function component body. This error could stem from several reasons:For tips on debugging and resolving this issue, visit https://reactjs.org/link/invalid-hook-call. ▶ 22 stack frames were collapsed. Module. src/index.js:7
- Possible mismatching versions of React and the renderer (such as React DOM)
- Violation of the Rules of Hooks
- Presence of multiple copies of React within the same app
Despite researching common solutions for this error, such as checking for duplicate React installations by running npm ls react, I was unable to resolve the issue. Upon finding multiple copies of React in my project directory (as shown in the terminal screenshot), I assumed that "deduped" meant deduplicated and hence not the root cause.
Interestingly, removing the problematic component resolved the error instantly. If anyone has insight on solving this issue, I would greatly appreciate it.
import React from 'react';
import Accordion from '@material-ui/core/Accordion';
import AccordionSummary from '@material-ui/core/AccordionSummary';
import AccordionDetails from '@material-ui/core/AccordionDetails';
Faq.js:
const Faq = (props) =>{
return (
<Accordion>
<Accordion>
<AccordionSummary
aria-controls="panel1a-content"
id="panel1a-header"
>
<p>Pregunta1</p>
</AccordionSummary>
<AccordionDetails>
<p>HOLAA</p>
</AccordionDetails>
</Accordion>
<Accordion>
<AccordionSummary
aria-controls="panel2a-content"
id="panel2a-header"
>
<p>Pregunta2</p>
</AccordionSummary>
<AccordionDetails>
<p>Holaaaa</p>
</AccordionDetails>
</Accordion>
</Accordion>
)
}
export default Faq;
MainCard.js:
import React from 'react';
import Faq from './Faq'
const MainCard = () =>{
return(
<div className="cardcontainer">
<div className="nosotros">
<div className="titulosnosotros">
<h1 className="titulo">Estudio sobre el diario <br />pionero de la transformación digital</h1>
<h2 className="subtitulo">¿Querés concoer más acerca de <br /> su reinvención?</h2>
<button className="download">¡Descargue aquí!</button>
</div>
</div>
<div className="informacion">
<ul className="informacionlist">
<li>
<img src="./images/cliente.png" />
<p className="informacion-texto">Cliente siempre en el centro</p>
</li>
<li>
<img src="./images/multiplataforma.png" />
<p className="informacion-texto">Más que un diario, una multiplataforma</p>
</li>
<li>
<img src="./images/barreras.png" />
<p className="informacion-texto">Atravesando barreras en la era digital</p>
</li>
</ul>
</div>
<div className="transformacion">
<h3 className="titulo-transformacion">Un diario que supo adaptarse</h3>
<img className="fotodiario" src="./images/diario.jpg" />
<h4 className="subtitulo-informacion">Desde 1869 hasta el presente digital</h4>
</div>
<div className="comentarios informacion">
<h3 className="titulo-comentarios titulo-transformacion">Comentarios</h3>
<ul className="informacionlist">
<li>
<img src="./images/icono.png" />
<p className="comentarios-texto">"¡Muy interesante!"</p>
</li>
<li>
<img src="./images/icono.png" />
<p className="comentarios-texto">"No puedo parar de leer"</p>
</li>
<li>
<img src="./images/icono.png" />
<p className="comentarios-texto">"Muchas cosas que no sabía"</p>
</li>
<li>
<img src="./images/icono.png" />
<p className="comentarios-texto">"¡Me encantó!"</p>
</li>
</ul>
</div>
<Faq />
</div>
)
}
export default MainCard;
App.js:
import logo from './logo.svg';
import './App.css';
import MainCard from './components/MainCard';
import Contact from './components/Contact';
import Footer from './components/Footer';
import Header from './components/Header';
function App() {
return (
<div className="App">
<Header />
<MainCard />
<Contact />
<Footer />
</div>
);
}
export default App;
package.json:
{
"name": "landingpage-lanacion",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"react-scripts": "^4.0.3",
"web-vitals": "^1.1.1"
},
"devDependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2",
"@material-ui/core": "^7.0.0"
},
"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"
]
}
}