Where to dispatch multiple actions in redux?

前端 未结 7 1579
终归单人心
终归单人心 2021-01-31 08:10

I am using redux with connect and redux-thunk middleware and containers.

Currently when an user perform an action, example one click on a butto

相关标签:
7条回答
  • 2021-01-31 09:05

    While solution by @GibboK did not work for me:

    const mapDispatchToProps = (dispatch) => ({
      action2: id => dispatch(Actions.action2(id)),
      action3: id => dispatch(Actions.action3(id)),
      action1: (dateId, attrId) => {
        return dispatch => {
          dispatch(Actions.action2(dateId));
          dispatch(Actions.action3(attrId));
        }
      }
    });
    

    I eventually went with redux-batched-actions. Worked like charm:

    const mapDispatchToProps = (dispatch) => ({
      action2: id => dispatch(Actions.action2(id)),
      action3: id => dispatch(Actions.action3(id)),
      action1: (dateId, attrId) =>
        dispatch(batchActions([
          Actions.action2(dateId),
          Actions.action3(attrId)
        ]))
    });
    
    0 讨论(0)
提交回复
热议问题