reactjs - React,Redux-Saga : Which is the best way to handle error in saga and inform component to display that error

标签 reactjs error-handling react-redux redux-saga

我有两种方法来解决这个问题

1)更新redux中的错误标志并在组件中使用

2)使用Promise调度操作,然后解决或拒绝来自传奇的 promise ,因此我们可以在组件中使用
例如:

doSomething: payload => {
      return new Promise((resolve, reject) => {
        dispatch(SomeActions.doSomething(payload, resolve, reject));
      });
    }

我应该使用哪种解决方案,以便可以正确地维护代码。

如果有更好的解决方案可以使用,请帮助我理解。

最佳答案

您应该坚持第一种方法。根据redux原则, Action 是普通对象。这意味着在 Action 中传递函数(例如,在传奇中解析和拒绝调用)被视为不良做法。

关于reactjs - React,Redux-Saga : Which is the best way to handle error in saga and inform component to display that error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61824806/

相关文章:

ReactJS 和 DRF : How to store JWT token inside HTTPonly cookies?

函数只能在主线程中调用,为什么呢?

c# - Application_Error异常处理,重定向无限循环和CSS加载问题

ios - React-Native with Redux : API objects appear in my console. 日志但不是我的观点

reactjs - react 虚拟化 onRowsRendered 占位符

javascript - JSON-LD 模式与 GatsbyJS 的丰富片段

javascript - 如何忽略 React Router 中的链接?

angular - 通过自定义 ErrorHandler 出现错误时显示自定义消息

javascript - 让yield.put在redux-saga中一个接一个地发生

reactjs - React 和 Redux HTTP header 授权