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

Data: withSelect throws "Invalid hook call" React error #17805

Closed
adekbadek opened this issue Oct 7, 2019 · 4 comments
Closed

Data: withSelect throws "Invalid hook call" React error #17805

adekbadek opened this issue Oct 7, 2019 · 4 comments
Labels
[Package] Data /packages/data [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed

Comments

@adekbadek
Copy link
Contributor

adekbadek commented Oct 7, 2019

Describe the bug
When trying to use withSelect from @wordpress/data (in a WP plugin code), error is thrown by React:

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

To reproduce
A. Locally with a WP setup: recreate the basic example to display authors
B. Or, see reproduction on codesandbox

Expected behavior
Error is not thrown.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome 77, Firefox 69
@adekbadek
Copy link
Contributor Author

Update: the problem might be due to react versions mismatch between my plugin code and Gutenberg plugin:

  1. Deactivating Gutenberg plugin solves the issue,
  2. as does externalizing react dependencies in webpack (with which the plugin code is bundled).

@adekbadek
Copy link
Contributor Author

Possibly duplicate of #15873

@swissspidy swissspidy added the [Package] Data /packages/data label Oct 11, 2019
@gziolo
Copy link
Member

gziolo commented Nov 12, 2019

Or, see reproduction on codesandbox

I can confirm that it’s the same issue as #15873. Let’s continue there.

@gziolo gziolo closed this as completed Nov 12, 2019
@gziolo gziolo added the [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed label Nov 12, 2019
@gziolo
Copy link
Member

gziolo commented Nov 12, 2019

@adekbadek, thank you for sharing detailed reproduction steps 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Data /packages/data [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed
Projects
None yet
Development

No branches or pull requests

3 participants