Skip to content
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

NPM link local react hooks library reporting errors: Hooks can only be called inside the body of a function component. #8607

Closed
mushan0x0 opened this issue Jan 9, 2019 · 4 comments

Comments

@mushan0x0
Copy link

mushan0x0 commented Jan 9, 2019

Bug report

This is a react hooks library rc-form-hooks, which was linked in the example and will now report an error.
It looks like a compiled problem because I yarn installed it without errors

What is the current behavior?

Hooks can only be called inside the body of a function component.

image

image

It should look like this:

image

image

If the current behavior is a bug, please provide the steps to reproduce.

  1. git clone https://github.com/mushan0x0/rc-form-hooks
  2. cd rc-form-hooks
  3. yarn && yarn start
  4. cd example
  5. yarn && yarn start

What is the expected behavior?

no error

Other relevant information:
webpack version: 4.19.1
Node.js version: 10.6.0
Operating System: mac os
Additional tools: react-scripts 2.1.3

@sokra
Copy link
Member

sokra commented Jan 9, 2019

Is there only a single react package in the bundle? Looks like you reference two react versions.

@mushan0x0
Copy link
Author

mushan0x0 commented Jan 10, 2019

@sokra All versions are 16.7.0-alpha.2

@sokra
Copy link
Member

sokra commented Jan 10, 2019

All versions are 16.7.0-alpha.2

Yes, but this was not the question. react breaks when you include it twice (even if the version is equal). Make sure to only include a single react in the bundle. Try resolve.alias: { react: require.resolve("react") }.

@mushan0x0
Copy link
Author

@sokra Thank you, this can solve this problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants