在传奇中替代thunk调度有什么选择?

问题描述 投票:0回答:2

在我的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。我将传奇应用到项目中,我想用传奇重写。由于没有API调用,因此我不想通过传奇发送到reducer。我想直接从此操作转到减速器。那么如何在没有派遣的情况下重写?

javascript reactjs react-native redux-saga redux-thunk
2个回答
0
投票

您可以在使用https://github.com/Yasser-G/react-native-redux的同时按照自己的逻辑来执行操作>


0
投票

使用Sagas处理副作用,您可以使用put直接从您的传奇中分发动作。

© www.soinside.com 2019 - 2024. All rights reserved.