return promise from store after redux thunk dispatch

后端 未结 3 865
慢半拍i
慢半拍i 2020-12-08 01:58

I am trying to chain dispatches with redux thunk

function simple_action(){
  return {type: \"SIMPLE_ACTION\"}
}

export function async_action(){
  return fun         


        
3条回答
  •  醉酒成梦
    2020-12-08 02:47

    This is a pattern I've been using recently:

    export const someThenableThunk = someData => (dispatch, getState) => Promise.resolve().then(() => {
      const { someReducer } = getState();
      return dispatch({
        type: actionTypes.SOME_ACTION_TYPE,
        someData,
      });
    });
    

    When you dispatch(someThenableThunk('hello-world')), it returns a Promise object that you can chain further actions to.

提交回复
热议问题