-
Notifications
You must be signed in to change notification settings - Fork 48.4k
Using hook from dependency throws error Invalid hook call #15706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can confirm this. I'm having the same issue. |
So you are getting this? And from the given code, where the error happens And where it works I would speculate this is happening |
@kunukn Yep |
I am also having the same issue |
Hi folks, I investigated quite a lot and finally I draw it out! So if you want to create a separate library (eg: # Install React in your library
cd path/to/my-lib
npm i react
# Link the React dependency from your library
cd node_module/react`
npm link
# Use the linked React dependency in your app
cd path/to/my-app
npm link react |
I had a similar issue but with react-router and I was able to fix it using
And here is the package.json of the app that is consuming the library:
|
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I have a dependency collecting a list of shared hooks.
Whenever I try to run them, I get an
Invalid hook call
error. If I copy it in the main repo, the hook works as expected.If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have dependencies other than React. Paste the link to your JSFiddle (https://jsfiddle.net/Luktwrdm/) or CodeSandbox (https://codesandbox.io/s/new) example below:
In hooks repository:
In react app:
What is the expected behavior?
I would define hooks into a separate repository, add the dependency in a react project, and get no error.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
Hooks repository:
React app:
Maybe I'm not defining the hooks in the proper way... or maybe having
react
dependency even in my submodule generates a double React.BTW: Next uses React
v16.8.6
, so React versions are the same in both repositoriesThe text was updated successfully, but these errors were encountered: