-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
I have the following setup following your examples for chaining async actions:
// final action
function finalAction (status) {
return {
type: 'AUTH_STATUS'
, status
}
// thunk action
function thunkAction () {
return (dispatch, getState) => {
return getStatusApi()
.then((status) => {
return dispatch(finalAction(status))
})
.catch((err) => {
return dispatch({type: 'AUTH_ERROR'})
})
}
}
// api function returning another promise
function getStatusApi () {
return myAsyncApiCall().then((res) => {
return res.status
})
}
// dispatch
store.dispatch(thunkAction())
.then(() => {
// the end
})What happens is that the flow is like this:
store.dispatch
thunkAction
getStatusApi
end
myAsyncApiCall
finalAction
reducer
For one reason or another store.dispatch resolves before myAsyncApiCall is resolved.
I either receive then a TypeError or if wrapping the whole into a promise an undefined action error.
Any idea?
Metadata
Metadata
Assignees
Labels
No labels