Guides
Rails
Javascript
Additional details
Deployment
React on rails pro
Api
Misc
Contributor info
Testimonials
Outdated
Shakacode logoShakaCodeDeveloped by

Copyright 2020 ShakaCode

Invalid hook call error

react.development.js:1465 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.

The main reason to get this is due to multiple versions of React installed.

cd <top level>
npm ls react

cd spec/dummy
npm ls react

For the second one, you might get:

react_on_rails@ /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy
├── [email protected]
└─┬ [email protected] -> /Users/justin/shakacode/react-on-rails/react_on_rails invalid
  └── [email protected]  extraneous

npm ERR! invalid: [email protected] /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails
npm ERR! extraneous: [email protected] /Users/justin/shakacode/react-on-rails/react_on_rails/spec/dummy/node_modules/react-on-rails/node_modules/react

Make sure there is only one version of React installed!

If you used yarn link, then you'll have two versions of React installed.

Instead use Yalc.

cd <top level>
yalc publish

cd spec/dummy
yalc link react-on-rails