question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: Invalid hook call in React Native; verified all known causes

See original GitHub issue

I’m getting the Invalid Hook Call warning, and I’ve gone down the list of the potential causes and have ruled out (as far as I can tell) all of them:

  1. Mismatching versions of react and react-dom
  • from my package.json
"dependencies": {
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
}
  1. Breaking rules of hooks
  • my component:
const CaptureScreen = () => {
    const [stuff, setStuff] = useState(0)

    return (
        <DefaultTemplate >
            <NuggetAdder />
        </DefaultTemplate>
    )
}
  1. Multiple versions of react
  • I’ve required react from node_modules/react-dom/index.js and set it to window.React1, and from the component CaptureScreen (above) I have done the steps listed in the “Invalid hook call documentation” and set up window.React2. When I log window.React1 === window.React2, I get back true.
  • I’m not certain this is reliable since I use yarn, but running npm ls react returns:
myproject@0.0.1 /Users/me/programming/projects/my-project/client
└── (empty)

React version: 16.13.1 React-native version: 0.62.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
Tycholizcommented, Jun 17, 2020

@bvaughn that fixed it!

I forget the exact reason why I added react-dom in there in the first place, but I have a feeling it was related to unit testing with Jest. I always questioned why it was in there as well, but figured that Jest was using it for mocks or something.

Phew, that solves a long and drawn out case! Hope this can help someone else.

1reaction
bvaughncommented, Jun 17, 2020

Why is react-dom involved here? Your title says “React Native” but you’ve mentioned react-dom a few times.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Hook Call Warning
There are three common reasons you might be seeing it: You might have mismatching versions of React and React DOM. You might be...
Read more >
Solving React Hooks' invalid hook call warning
We'll solve the 'invalid hook call warning' error and get your project ... us that there are actually three possible causes of this...
Read more >
Invalid hook call error, but everything seems to be good
For a React-native project running on React-native web, I want to run an init function in my component with the useEffect() hook. In...
Read more >
invariant violation: invalid hook call. hooks can only be ...
Expected Behaviour · You might have mismatching versions of React and the renderer (such as React DOM) · You might be breaking the...
Read more >
Invalid hook call. Hooks can only be called inside of the body ...
When you face this issue you just need to reinstall this "npm install react-bootstrap@next bootstrap@5.1.0" then your error will be resolve. karishma tejwani...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found