Using thunks in mapDispatchToProps
I suggest declaring your actual thunk (someOtherAction
) differently. In the following example, asyncAction
is an async action creator which returns a thunk. The thunk can then dispatch other actions (after a promise resolves for example).
function asyncActionCreator () {
return (dispatch, getState) => {
dispatch(someAction());
someAsyncStuff().then(() => {
dispatch(someOtherAction(getState().foo);
});
}
}
function mapDispatchToProps(dispatch) {
return {
foo: () => dispatch(asyncActionCreator())
}
}