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

Can’t extract a custom React hook #1389

Closed
doasync opened this issue Dec 17, 2018 · 2 comments
Closed

Can’t extract a custom React hook #1389

doasync opened this issue Dec 17, 2018 · 2 comments

Comments

@doasync
Copy link

doasync commented Dec 17, 2018

Do you want to request a feature or report a bug?
bug maybe

What is the current behavior?
https://codesandbox.io/s/km21z2l2rv

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)

@doasync
Copy link
Author

doasync commented Dec 22, 2018

I solved this issue by removing the caret for React dependency in my package.json:

    "react": "16.7.0-alpha.2",
    "react-dom": "16.7.0-alpha.2",

See this comment for more info: facebook/react#14454 (comment)

@doasync doasync closed this as completed Dec 22, 2018
@CompuIves
Copy link
Member

Ahh, so that was it! Glad that it's resolved now 😄.

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