You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can’t extract a custom hook (in codesandbox) #14454
What is the expected behavior?
I extracted my utils.js to a package. When I replace imports from "./utils" with a real npm package, I get an error: Hooks can only be called inside the body of a function component. (see codesandbox)
Since files are identical, I expect my external file to work the same.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.7.0-alpha.2
Chrome Version 70.0.3538.77 (Official Build) (64-bit)
When I started developing of my npm package, I installed React with npm i react@next react-dom@next and had "react": "^16.7.0-alpha.2" (with caret) in my package.json. But it turned out that I had different version of React in my node_modules folder somehow: "version": "16.7.0". I removed those carets, updated my package and the issue is gone.
why when i use styled components in react js it shows this error:- Invalid hook call. Hooks can only be called inside of the body of a function component. error
But when I don't use styled components my react app works fine
Activity
aweary commentedon Dec 20, 2018
@doasync there are most likely multiple versions of React running on the page, which can trigger this error. See #13991.
doasync commentedon Dec 22, 2018
@aweary Thank you. That's the issue.
When I started developing of my npm package, I installed React with
npm i react@next react-dom@nextand had"react": "^16.7.0-alpha.2"(with caret) in my package.json. But it turned out that I had different version of React in mynode_modulesfolder somehow:"version": "16.7.0". I removed those carets, updated my package and the issue is gone.shubhanshu2000 commentedon Sep 24, 2021
why when i use styled components in react js it shows this error:- Invalid hook call. Hooks can only be called inside of the body of a function component. error
But when I don't use styled components my react app works fine