Redux中的条件动作创建者

Redux中的条件动作创建者,redux,react-redux,Redux,React Redux,在action creators中编写条件是最佳实践吗?如果没有,还有什么替代方案 我的场景是,我有一个文件上传器,根据选择,我将数据推送到reducerA或reducerB return function (dispatch, getState) { const { selectedStage } = getState(); if (selectedStage.stage === Constants.STAGE_CARRIER) { **

在action creators中编写条件是最佳实践吗?如果没有,还有什么替代方案

我的场景是,我有一个文件上传器,根据选择,我将数据推送到reducerA或reducerB

return function (dispatch, getState) {
        const { selectedStage } = getState();
        if (selectedStage.stage === Constants.STAGE_CARRIER) {
            **dispatch(uploadCarrier(payload));**
        } else {
            **dispatch(uploadWeb(payload));**
        }

    };

这取决于你想/需要在哪里做决定。我有三个选择。三人都觉得合法。1.在action creator(如您的示例)2中。连接时,检查状态并给出相应的操作3。组件内部,如
this.props.stage===Constants.stage\u载体?this.props.uploadCarrier():this.props.uploadWeb()
您应该在组件内部分派不同的操作(smart)。您的动作创建者不应该知道任何差异,它只应该是一个普通对象。您应该在组件中写入的所有条件。这很好,因为您的其他组件可能会使用相同的操作,并且您不希望为特定组件添加代码。例如:
addFile:(文件,类型)=>{if(类型=='A'){dispatchProps.AddA(文件)}else{dispatchProps.addB(文件)}