什么时候应该使用 Redux Saga 而不是 Redux Thunk,什么时候应该使用 Redux Thunk 而不是 Redux Saga? [英] When should I use Redux Saga instead of Redux Thunk, and when should I use Redux Thunk instead of Redux Saga?

查看:37
本文介绍了什么时候应该使用 Redux Saga 而不是 Redux Thunk,什么时候应该使用 Redux Thunk 而不是 Redux Saga?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与过去不同,这就是为什么.这个问题是什么时候.由于两者本身都是很好的框架,因此问题是我什么时候应该使用 thunk 而不是 saga.因为我的一个朋友一直坚持要我在我们的应用程序中使用 saga 但没有明显的原因.先谢谢了

The question is different from the past which is why. The question for this one is When. Since both are good frameworks by themselves the question is when should I use thunk than saga. Because one of my friend keeps insisting me to use saga in our app but no apparent reason why. Thanks ahead

推荐答案

根据一些阅读材料和我的经验...

Based on some readings and my experience...

使用 Thunk 而不是 Saga 来处理简单琐碎的任务,例如:

Use Thunk instead of Saga for simple and trivial tasks like:

  • AJAX 调用
  • 数据轮询并且仅当它们由用户交互直接启动时.

使用 Saga

  • 相互交织的任务,文档的登录示例非常完美
  • 包含许多步骤并等待其他条件发生的流程(有限状态机"流程)
  • 在后台工作并独立于用户交互(或后台/交互的混合)进行的任务

这篇关于什么时候应该使用 Redux Saga 而不是 Redux Thunk,什么时候应该使用 Redux Thunk 而不是 Redux Saga?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆