-
Notifications
You must be signed in to change notification settings - Fork 507
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
Can't use hooks when react
& react-dom
are dev dependencies
#64
Comments
The right solution is to put |
That doesn't seem to fix it for me. I still get the same error. |
have you tried to drop node_modules and lock files and reinstall deps? |
Yes, we should add react to peer deps and dev deps in the template and keep them as regular deps in the example directory. This is how I do it in Formik. IIRC Formik doesn’t place react-dom as a peer dep, only a dev dep, so it can be used with react native. |
peerdeps in v0.5.5 9f5c6de |
I think I found the problem. I was testing it using |
Sorry. I did get it work in an CRA-Project with the published package. But creating a project based on |
Facing the same problem; I don't think it is caused by tsdx itself - hooks are quite picky when multiple react instances are present - see facebook/react#14257. Tried doing the recommendations from there; Linked the package react using The solution which worked for me:
Probably not perfect, but at least it works quite fast. |
Yeah, the Thanks for your workaround! |
You don’t need to run yarn link if you build and import from the root |
I had the same issue, @petyosi solution worked for me. |
I think the solution I like best now is to use Parcel's alias like so:
|
use parcel's aliasing for react template example deps. closes #64
made a PR to do just that |
use parcel's aliasing for react template example deps. closes #64
This doesn't work if you're trying to deploy the example site to Netlify or something similar. Is there any other way to accomplish this? |
True |
@mikecousins you can always add a script to install the latest version of your lib |
Current Behavior
Thank you for this project!
I'm not sure if I missed or didn't understand something, but when choosing the
react
template,react
&react-dom
are added as dev dependencies. When you then try to use a hook inside your library, you get areact-invalid-hook-call
error. It works fine when removing them as dev dependencies and runningyarn
again.Example:
Expected behavior
I would expect the template to enable me to use hooks.
Suggested solution(s)
No idea if "just removing the dev dependencies" is the proper solution. It at least worked for me.
Your environment
0.5.4
3.4.5
74.0.3729.108
1.12.3
10.14.4
The text was updated successfully, but these errors were encountered: