Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid hook call on react 17 #4

Open
damdinsharav opened this issue Feb 2, 2021 · 5 comments
Open

Invalid hook call on react 17 #4

damdinsharav opened this issue Feb 2, 2021 · 5 comments

Comments

@damdinsharav
Copy link

Hi,
I'm getting following error in React 17.
What could be the issue? Maybe incompatibility. I am getting started with React and have no clue.

Uncaught Error: Invalid hook call. ...

...
The above error occured in the <Radar> component:
at Radar(http://localhost:3000/static/js/0.chunk.js:63974:21)
at div
at Techradar
at App

index.js

import React from 'react;
import ReactDOM from 'react-dom';
import TechRadar from "./TechRadar";

const App = () => {
   return <TechRadar />;
};

ReactDOM.render(<App />, document.querySelector(#root));

TechRadar.js

import React from 'react';
import Radar from 'react-tech-radar';

const TechRadar = ()=> {

    const setup = {
        rings: ['adopt', 'trial', 'assess', 'hold'],
        quadrants: ['tools', 'techniques', 'platforms', 'languages'],
        data: [
            {
                name: 'D3',
                quadrant: 'tools',
                ring: "assess"

            },
            {
                name: 'TypeScript',
                quadrant: 'languages',
                ring: "trial"
            },
            {
                name: 'Storybook',
                quadrant: 'tools',
                ring: "adopt"
            }
        ]
    };

    return (
        <div className="TechRadar">
            <Radar {...setup} />
        </div>
    );
}

export default TechRadar;
@antongitnow
Copy link

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

@omerg
Copy link
Owner

omerg commented May 21, 2021

Hi @antongitnow ,

That must be due to the fact that there are two versions of react or react-dom in your runtime environment. I notice that we need to remove react and react-dom from dependencies field inside package.json because they are already added to peer-dependencies. Please feel free to make the change.

@onikiienko
Copy link

You can use yarn resolutions to fix this problem, if you're using npm, you can check npm-force-resolutions.
You just have to specify your react and react-dom versions like this

{
...
  "resolutions": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2"
  },
...
}

gw-versent added a commit to gw-versent/react-tech-radar that referenced this issue Sep 16, 2022
I believe removing react and react-dom from devs to dev devs should resolve the issue with the 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.
omerg pushed a commit that referenced this issue Dec 16, 2022
I believe removing react and react-dom from devs to dev devs should resolve the issue with the 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.
@TotomiEcio
Copy link

Hi ! I'm using this versions of react and react-dom and I'm still getting the same error

"react": "^18.2.0",
"react-dom": "^18.2.0",
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://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (react.development.js:1280:1)
    at useContext (react.development.js:1286:1)
    at Radar (Radar.js:57:1)
    at renderWithHooks (react-dom.development.js:14141:1)
    at mountIndeterminateComponent (react-dom.development.js:17432:1)
    at beginWork (react-dom.development.js:18728:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3733:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3777:1)
    at invokeGuardedCallback (react-dom.development.js:3834:1)
    at beginWork$1 (react-dom.development.js:23713:1)

Thanks

@omerg
Copy link
Owner

omerg commented Apr 14, 2023

Should be fixed now 👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants