I'm getting an 'Invalid hook call. Hooks can only be called inside of the body of a function component' error when I try to use React Hooks with react-360. I'm building a 360 app with multiple surfaces and I want to connect them using the useReducer hook.
I get the following console error and the page loads an empty cylindrical surface.
Invariant Violation: 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:
You might have mismatching versions of React and the renderer (such as React DOM)
You might be breaking the Rules of Hooks
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.
This error is located at:
in BasicsHelper (at index.js:24)
in Basics (at renderApplication.js:33)
in RCTView (at View.vr.js:543)
in View (at AppContainer.js:102)
in RCTView (at View.vr.js:543)
in View (at AppContainer.js:122)
in AppContainer (at renderApplication.js:32)
Reproduction
I initialized a brand new react-360 project and just tried to use the useState hook in my app. I did not change any other part of the code.
Additionally, I tried the following to fix this:
npm i react@latest react-dom@latest react-native@latest
After I did this and I ran npm run start, I got this error and I could not start the app.
I tried the solutions posted there to fix this but none of them seemed to work. One of the solutions posted was to downgrade react-native to 0.55.0 and when I did that and ran npm run start, I was left with my initial React Hooks error.
Description
I'm getting an
'Invalid hook call. Hooks can only be called inside of the body of a function component'
error when I try to use React Hooks with react-360. I'm building a 360 app with multiple surfaces and I want to connect them using the useReducer hook.Expected behavior
This should have rendered the default "Welcome to React 360" home page when I loaded 'http://localhost:8081/index.html'.
Actual behavior
I get the following console error and the page loads an empty cylindrical surface.
Invariant Violation: 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:
This error is located at: in BasicsHelper (at index.js:24) in Basics (at renderApplication.js:33) in RCTView (at View.vr.js:543) in View (at AppContainer.js:102) in RCTView (at View.vr.js:543) in View (at AppContainer.js:122) in AppContainer (at renderApplication.js:32)
Reproduction
I initialized a brand new react-360 project and just tried to use the useState hook in my app. I did not change any other part of the code.
Solution
What needs to be done to address this issue? Ideally, provide a pull request with a fix.
Additional Information
Additionally, I tried the following to fix this: npm i react@latest react-dom@latest react-native@latest