Bug: Invalid hook call in React Native; verified all known causes
See original GitHub issueI’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:
- Mismatching versions of
react
andreact-dom
- from my
package.json
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
}
- Breaking rules of hooks
- my component:
const CaptureScreen = () => {
const [stuff, setStuff] = useState(0)
return (
<DefaultTemplate >
<NuggetAdder />
</DefaultTemplate>
)
}
- Multiple versions of react
- I’ve
required
react fromnode_modules/react-dom/index.js
and set it towindow.React1
, and from the componentCaptureScreen
(above) I have done the steps listed in the “Invalid hook call documentation” and set upwindow.React2
. When I logwindow.React1 === window.React2
, I get backtrue
. - I’m not certain this is reliable since I use
yarn
, but runningnpm 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:
- Created 3 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
Why is
react-dom
involved here? Your title says “React Native” but you’ve mentionedreact-dom
a few times.