mariela magallon
mariela magallon

Reputation: 1

Error: Invalid hook call. Hooks can only be called inside of the body

I'm working on a react App, and It was working fine till I installed react-router-dom and tried to import it to my App.js file, I'm getting this error:

× 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 to debug and fix this problem.

I tried some of this work arounds but haven't being successful, and I'm not breaking the rules of Hooks can someone please help me.

https://github.com/facebook/react/issues/15315

my json package below:

{
  "name": "rmdb-react",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.0",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": " react-scripts start", 
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "preinstall": "npx npm-force-resolutions"
    
  },
  "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"
    ]
  },
  "resolutions": {
    "react": "^17.0.2"
  }

}


Upvotes: 0

Views: 2175

Answers (1)

Gaurav Mithas
Gaurav Mithas

Reputation: 75

There is no react-router-dom in your package.json. Also, could you share the code where the error is thrown.

Upvotes: 1

Related Questions