-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Calling dispatch method immediately results in "Reducer may not dispatch actions" #122
Comments
It's probably |
Any news on this? I have an action to handle login and then change route to new screen where component needs to fetch some data in componentWillMount() by dispatching an action to do so. This fails unless I use setTimeout, as DaBs showed above. redux 3.6.0 |
@lbrdar As artemjackson said, I believe it's probably a redux issue, but in conjunction with thunk (or any other middleware for that sake), however it should be fixed in redux. This can be closed, but should be considered to be reopened at the redux repo. |
Any update on this? |
FWIW, I was seeing these errors when I put a |
@benjiwheeler You shouldn't put |
This comment has been minimized.
This comment has been minimized.
Why was this comment marked "resolved"? I would expect using 0, instead of 1, would also work. Does it? |
As title states, calling a dispatch action with the current version (2.1.0), will result in redux throwing the error "Reducers may not dispatch actions" from here. It seems that since the call is immediate, that redux considers this to be a part of the reducer function it is currently executing. Encapsulating the dispatch call inside a setTimeout for just a single miliseconds works fine and throws no error.
Example:
My use-case is updating the current state with
isFetchingItems: true
by dispatching the first function and then dispatch another function afterwards when the fetch has returned.The text was updated successfully, but these errors were encountered: