gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:40:40 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com