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

Improve message "dispatcher.useState is not a function" when mixing react@next with react-dom@16.5.2 #14039

Closed
geoffdavis92 opened this issue Oct 30, 2018 · 8 comments
Labels
Resolution: Stale Automatically closed due to inactivity Type: Enhancement

Comments

@geoffdavis92
Copy link

geoffdavis92 commented Oct 30, 2018

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

What is the current behavior?
Getting TypeError: dispatcher.useState is not a function when trying to call useState; this is happening in a create-react-app, as well as in the CodeSandbox example below.

Example:
https://codesandbox.io/s/7kp55lwwpj

What is the expected behavior?
useState hook function should execute without error as defined in the API documentation

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

React: v16.7.0-alpha.0
React-DOM: 16.5.2 (CSB), 16.7.0-alpha.0 (local)
React-Scripts: 2.0.3 (CSB), 2.1.0 (local)

@sophiebits sophiebits changed the title Getting TypeError: dispatcher.useState is not a function when calling useState "dispatcher.useState is not a function" when mixing react@next with react-dom@16.5.2 Oct 31, 2018
@sophiebits
Copy link
Collaborator

@geoffdavis92 You need to update react-dom to the same version.

We can likely have a better error for this though. Leaving this issue open to track that.

@CarberryChai
Copy link

you can yarn add react-dom@next and then have a try……

@geoffdavis92
Copy link
Author

@sophiebits Thank you, that was the issue. For some reason I thought I tried both packages at next but I suppose I did not.

This is ready to be closed IMO.

@gaearon gaearon changed the title "dispatcher.useState is not a function" when mixing react@next with react-dom@16.5.2 Improve message "dispatcher.useState is not a function" when mixing react@next with react-dom@16.5.2 Nov 2, 2018
@threepointone
Copy link
Contributor

Broadly, this is about warning when we have mismatched versions of react and react-dom installed, yes? This particular error happens right now because we have peerDependencies set with "react": "^16.0.0". This should be flagged by npm when installing, imo we should update peerDependencies to "react": "^16.8.0" (or whatever version) when we release hooks.

(we could verify versions in runtime too, but that seems like overkill)

I'll send out a PR closer to hooks launch to fix this.

@threepointone
Copy link
Contributor

discussed with dan a bit more, the peer dependency wouldn't fix it, since this actually lives on react which doesn't have a peer dep, sigh. I'll send a PR with a better error message.

@threepointone
Copy link
Contributor

the latest version (16.8.0-alpha.0) of react doesn't throw this error anymore (though it does throw an invariant Hooks can only be called inside the body of a function component. which isn't that much better).

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Type: Enhancement
Projects
None yet
Development

No branches or pull requests

5 participants