react处理dispatch返回值的方式

如何处理dispatch的返回值,1.要么用then的方式去处理,2.要么用async await的方式。

 function comfirmInsertBatCh() {
        const { err, values } = getParamsBatch();
        if (!err) {
            let params = transForAftereEndBatch({ valuesParams: values, batchTableData, detail: true });
            (dispatch({ type: 'application/saveFlowForBatchAccess', payload: params }) as any).then(res => {
                if (res?.ok) {
                    message.success(res.data) && window.close();
                }
            })
        } else {
            message.error('请填写必填项');
        }
    }
    ```

//addDataSource 确认新增数据源
    async function addDataSource(e) {
        e.preventDefault();
        let testResult = await testonnectivity('submit');
        if (!testResult) {
            return;
        }
        form.validateFields(async (err, values) => {
            if (!err) {
                let submitResult: any = await dispatch({
                    type: 'datasourceDetail/addDataToDatasource',
                    payload: {
                        creator: DatasourceDetail.creator,
                        flowId: DatasourceDetail.flowId,
                        ...values,
                        accessId,
                        isMulti: mysqlBranch,
                        ...AccessToDatasourceData
                    }
                });
                if (!submitResult?.success) {
                    message.error(submitResult?.msg)
                }
                else {
                    message.success(submitResult?.data) && window.close();
                }

            }
        })
    }

你可能感兴趣的:(react)