如何在Redux中有条件地调用动作

时间:2018-09-07 11:23:13

标签: javascript reactjs redux

我有这个动作创建者:

export const deleteUserFromStoreThenUpdateFirebase = user => {
  return (dispatch, getState) => {
    return dispatch(deleteUser(user)).then(() => {
      return deleteUserFromFirebase(user);
    })
  };
};

和这个:

export const deleteUser = user => {
  return async dispatch => {
    dispatch({ type: DELETE_USER, user: user, reqConfirm: true });
  };
};

和一些中间件:

const confirmMiddleware = store => next => action => {
    if(action.reqConfirm){
      if(confirm('are you sure?')){
        next(action)
      }
    }
    else {
      next(action)
    }
}

我只希望以下行调用return deleteUserFromFirebase(user);:如果此行返回true:dispatch(deleteUser(user)).then((),但是当我在中间件中的确认上单击cancel时。它仍然称呼它。我该如何更改?

0 个答案:

没有答案