【发布时间】:2020-04-29 22:37:00
【问题描述】:
在我的 react 项目中,我有以下代码。
import uuid from 'uuid';
import { SET_ALERT, REMOVE_ALERT } from './types';
export const setAlert = (msg, alertType, timeout = 5000) => dispatch => {
const id = uuid.v4();
dispatch({
type: SET_ALERT,
payload: { msg, alertType, id }
});
setTimeout(() => dispatch({ type: REMOVE_ALERT, payload: id }), timeout);
};
这里已经使用了thunk。我将 saga 应用到项目中,我想用 saga 重写。由于没有 API 调用,我不想通过 saga 发送到减速器。我想直接从这个动作去减速器。那么如何在没有 dispatch 的情况下重写呢?
【问题讨论】:
标签: javascript reactjs react-native redux-saga redux-thunk