support for asynchronous actions
See original GitHub issuei keep getting the following error for async actions
action with type undefined did not modify the data in any reducer.You may have mutated state directly or you may have a typo in your reducer
i think this is because of the following code in the middleware.
const prevState = getState();
const result = next(action);
const nextState = getState();
Since the action here is a function which returns a promise we need to compare the nextState
with the prevState
only after the promise has been resolved. Something like the following might fix the issue
const prevState = getState();
const result = Promise.resolve(next(action));
result.then(() => {
const nextState = getState();
if (prevState === nextState) {
callback(action);
}
});
return result;
The above issue will only happen if thunk middleware is added after the redux-unhandled-action middleware. Something like the following
applyMiddleware(reduxUnhandledAction(), thunk)
But if we add thunk at the beginning, then this issue will not happen as the async action will not be forwarded to the other middlewares. So the following will work fine
applyMiddleware(thunk, reduxUnhandledAction())
So I am not sure if there is need to fix it. If this is the expected behavior, then the issue can be closed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
How to use promises - Learn web development | MDN
With a promise-based API, the asynchronous function starts the operation and returns a Promise object. You can then attach handlers to this ...
Read more >Redux Fundamentals, Part 6: Async Logic and Data Fetching
The official Redux Fundamentals tutorial: learn how to use async logic ... It only knows how to synchronously dispatch actions, update the ...
Read more >Synchronous and Asynchronous Actions - Micro Focus
The actions that you send to Media Server can be synchronous or asynchronous. Media Server does not respond to a synchronous action until...
Read more >Asynchronous Programming - Eloquent JavaScript
One approach to asynchronous programming is to make functions that perform a slow action take an extra argument, a callback function. The action...
Read more >Task asynchronous programming model - Microsoft Learn
Asynchrony is essential for activities that are potentially blocking, such as web access. Access to a web resource sometimes is slow or delayed....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@oyeanuj should be position agnostic now
@conorhastings @amit1911 So, is the middleware position agnostic? Or does it come at the end?