Reactjs, encountering a hitch in utilizing material UI: Incompatible hook call detected

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:
  • 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
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

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"
    ]
  }
}

Answer №1

Give this a shot:

npm remove @material-ui/core
npm remove @material-ui/icons
npm remove @material-ui/lab

After that, do the following:

npm install @material-ui/core @material-ui/icons @material-ui/lab

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When attempting to execute a promise within a test, encountering a 400 error in a NodeJS environment

I recently started using Contentful, a new JavaScript library for creating static websites. My goal is to incorporate it into my Node.js project. To achieve this, I developed an app file called getContent.js: 'use strict'; var contentful = req ...

The json_decode function in PHP unexpectedly returns null when provided with valid JSON input

I am attempting to send a JSON object using AJAX post in JavaScript as shown below: $.ajax({ type: 'POST', url: 'testPost.php', data: {json: cond}, dataTyp ...

What steps can be taken to receive an alternative result when selecting a checkbox?

Currently, I am tackling the issue with checkboxes in Vuetify. The challenge lies in achieving a different output for the second {{ selected.join() }}. For example, when I select the checkbox labeled "Social Media," I receive the text "On our social medi ...

What is the process by which React recreates the React element tree (virtual DOM) with every state update?

From what I've gathered, every time a state is updated in React, it generates the react element tree (virtual DOM) and then compares it with the new one using a diffing algorithm. However, there's something I find puzzling. Let's say we hav ...

I would like for this message to appear periodically following the initial execution

I have developed a unique welcome feature using HTML and CSS that I would like to showcase intermittently. --------------------------- My Desired Outcome --------------------------- Initially, this feature should be triggered once (when a user first acce ...

Is it possible to check dynamically if a string contains multiple substring matches?

Currently, I am in the process of developing a search suggest feature that will provide the best match based on certain criteria. Below is the code snippet along with my explanatory comments. /* string = {"Canna Terra PLUS 50 Litres", "Canna Vega ...

Exploring Next.js 13: Tailoring Next.js layouts to suit your route structure

In my latest project with Next.js version 13, I am encountering a situation involving a route called problems/[slug]. At the initial level of this route (e.g., problems/react), there is a sidebar and content section that are being shown using a custom layo ...

Best practice for postponing the assignment of values in React after making an API request?

Looking for guidance on handling an API call in React? Check out the example code below. How can I ensure that 'apiResult' is set before values value1 and value2 are assigned? I initially tried using 'await' with axios, but React is th ...

Refreshing Data in NextJs as Search Parameters Change

I'm currently working on developing an app that features a search bar where users can input a name. The app then queries two different APIs to gather information about that name, displays it to the user, and saves the search along with the results to ...

Filtering data on objects in Angular can be achieved by utilizing the built-in

Retrieving data from the backend using this function: private fetchData(): void { this.dataService.fetchData().pipe( tap((response: any) => { this.persons = response.results; this.familyMembersTrue = this.persons.filter(x =&g ...

Tips on showcasing an image from MongoDB in ReactJS

I have been working on developing a drawing application using React, Node, and MongoDB. This app is designed to save images along with the name and username in the database. When the home page is accessed, it needs to retrieve and display the image on the ...

Guide on creating multiple instances of vue-multiselect with a simple button click

I am trying to implement a vue-multiselect dropdown with the addition of a new dropdown upon clicking an "add more" button. However, I am currently unsure of the best approach to achieve this. Problem/Question: When adding 2 dropdowns, if the same option ...

Retrieve the Corresponding Content Inside the Div Element

I have a div with text that needs to be matched with comma-separated values: <div class="val"> This is paragraph 1 </div> <div class="val"> This is paragraph 2 </div> Using an Ajax call, I retrieve the ...

How to remove a loop-rendered component from the DOM in Vue

My website has an image upload form where users can select multiple images. Once the images are selected, they are previewed and users can provide meta info such as Category and Type for each image. This functionality is implemented in the upload.vue file ...

Here's a guide on customizing the appearance of the date picker in NativeBase components for React Native by

Is there a way to show icons while using the date picker component from the Native Base UI library? ...

Having troubles with your jQuery script on Internet Explorer?

I am facing an issue with my script. It is located in an external file and called at the beginning of my HTML page. The script involves an Ajax request that constantly checks a database for updates. When an update is detected, it triggers a specific functi ...

Exploring the benefits of looping with node.js require()

Currently, I have defined the required files as shown below. constantPath = './config/file/' fileAA = require(path.resolve(constantPath + 'A-A')), fileBB = require(path.resolve(constantPath + 'B-B')), fileCC = require(path.r ...

The mapStateToProps function in a Higher Order Component is receiving an OwnProps argument with a property that is not defined

I'm a new user of react-redux trying to connect a higher-order component to the react-redux store. In the mapStateToProps function, I'm using the ownProps argument to filter the state. However, the property I'm trying to use within OwnProps ...

Angular displaying a blank screen, even though the complete dataset is available

I am currently working on my first website using Angular and I've encountered a problem. When I click on 'view project', it should return the data specific to that item. The strange thing is, when I log my JavaScript console, I can see all t ...

I am attempting to adjust the color of the active tab, but I seem to be encountering issues in my code. Can anyone help me

The currently active tab should change along with the text inside the box, but it's not working as expected. I'm struggling to find out why. Here is a fiddle to demonstrate my progress so far: var btn1 = document.getElementById("btn1"); va ...