React-redux: Receiving 'Invalid hook call' when using connect and react-redux 7.0.3

Created on 7 Jun 2019  路  13Comments  路  Source: reduxjs/react-redux

There appears to be an error (Invalid hook call) if I use react-redux version 7.0.3 in conjunction with using the connect object.

If I use version 6.0.1 I don't receive the same error and works as expected.

Expected behavior: No errors.

Steps to reproduce:

https://github.com/scottyj503/react-redux-error

This is a test project that I created just for this example. If you clone, npm install and run you will see the specific error.

If you remove react-redux and add version 6.0.1 the code works as expected.

As a workaround I have downgraded to version 6.0.1.

Most helpful comment

@here : was anyone able to solve it, i get the Invalid hook call error with React-redux version 7.X.X but downgrading the version solves the issue. I see only one version of react in my project.

All 13 comments

Well, that's very odd.

The repro project appears fairly minimal, and I can't see anything obviously wrong with it after cloning and running it.

However, if I set up a new Create-React-App project and copy-paste your exact source over to that, then it runs just fine.

We do know the library works just fine in general. So, I'm going to have to chalk this up to your Webpack build configuration, somehow. Sorry I can't figure out anything more beyond that.

Thanks for the quick response.
I looked further into my Webpack config and it appears that the hash option in the HtmlWebpackPlugin is causing the issue...

@markerikson I'm seeing this in Expo. Any thoughts? In my case, there's no configuration changes I can make that I can see to attempt to troubleshoot this.

There's also this issue, so at least 3 people seeing the issue so far. I tried [email protected] and [email protected], but connect always throws the same error.

[email protected]
[email protected]
[email protected] (Expo fork)

Unfortunately useDispatch() throws the exact same error.

I had two versions of React somehow. If you're running into this, it's very likely this is your issue. Use yarn why react to determine what versions you have installed and ensure they match.

I came across the same issue and downgrading to version 6.0.1 works for me. I also tried version 7.0.0, 7.1.0 and 7.2.0, all of them has this problem.

Btw, I saw similar issue as well: https://github.com/reduxjs/react-redux/issues/1479

If anyone comes across this, you might have named your function starting with use. React thinks this is a custom hook.

@here : was anyone able to solve it, i get the Invalid hook call error with React-redux version 7.X.X but downgrading the version solves the issue. I see only one version of react in my project.

Getting this too, literally just an empty tutorial electron project and it doesn't work.

6.0.0 works fine 馃憤

As I've already said: we know React-Redux v7 works correctly. This issue means there's some kind of a build setup problem.

I had this issue as well using electron-webpack, react 16.13.1, downgrading to 6 worked.

My previous comments still stand. The library works fine. Every single instance of this error has been build-related.

"Downgrading to v6" is not a real solution. It avoids the error because v6 did not use hooks internally, but v6 is a dead release and is not maintained. It also has known performance issues.

Please figure out what's wrong with your build setup and use v7 instead.

As a note, I had this issue after upgrading the NodeJS version. Tried everything. Removing all deps from package.json, clearning locks and node_modules. Nothing worked.

Then i tried to use npm install instead of yarn and now everything works fine. Probably something cache related?

Was this page helpful?
0 / 5 - 0 ratings