长期使用Redux-Saga值得吗?

发布于 2025-01-31 12:22:28 字数 154 浏览 2 评论 0 原文

Redux-Saga是Redux副作用经理,据说被弃用,不再维护。

然而,不管大约3年前出版了最后1.1.3版的Redux-Saga版本,超过100万开发人员每周下载此NPM包装。

如果我继续长期使用Redux-Saga,即使它不再由作者维护,我可能会面临什么问题?

Redux-Saga, a Redux side effect manager, is said to be deprecated, and no longer being maintained.

Yet, over 1 million developers download this NPM package weekly, regardless of the fact that the last 1.1.3 version of Redux-Saga was published almost 3 years ago.

What issues might I face if I keep on using Redux-Saga for the long term, even if it is no longer being maintained by its authors?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

讽刺将军 2025-02-07 12:22:28

我是Redux维护者。

今天,我们在几乎所有用例中都特别推荐使用Sagas使用Sagas

!如果您确实需要该功能,那么拥有该工具很重要。但是大多数时候,您每天都不需要电锯。

实际上,我只是就这个特定主题进行了讨论:

Reactathon 2022:redux async逻辑的演变

在那段演讲中,我描述了在Redux应用中处理异步逻辑和副作用的不同技术,并为您今天使用的内容提供了一套建议。我将粘贴到这里的最后一个幻灯片中供参考:

我们今天的建议

您要解决什么用案例?

数据获取

  • 使用RTK查询作为数据获取和缓存的默认方法
  • 如果RTKQ由于某种原因不完全适合,请使用 createAsyncthunk
  • 仅掉回手写的thunk,如果什么都没有。 Works
  • 不使用Sagas或可观察到数据获取!

对操作/状态变化做出反应,异步工作流

通过State Access

  • 用thunks来 解决您的用例的逻辑,以解决您的用例复杂的同步和中等异步逻辑,包括访问 getState 并派遣多个操作

I'm a Redux maintainer.

Today, we specifically recommend against using sagas in almost all use cases!

To be clear: Sagas are a great power tool, like a chainsaw. If you really need that power, then having that tool is important. But most of the time, you don't need a chainsaw on a daily basis.

I actually just gave a talk on this specific topic:

Reactathon 2022: The Evolution of Redux Async Logic

In that talk I described different techniques for dealing with async logic and side effects in Redux apps, and gave our set of recommendations for what you should use today. I'll paste in the last slide here for reference:

Our Recommendations Today

What use case are you trying to solve?

Data Fetching

  • Use RTK Query as the default approach for data fetching and caching
  • If RTKQ doesn't fully fit for some reason, use createAsyncThunk
  • Only fall back to handwritten thunks if nothing else works
  • Don't use sagas or observables for data fetching!

Reacting to Actions / State Changes, Async Workflows

  • Use the RTK "listener" middleware as the default for responding to store updates and writing long-running async workflows
  • Only use sagas / observables in the very rare situation that listeners don't solve your use case well enough

Logic with State Access

  • Use thunks for complex sync and moderate async logic, including access to getState and dispatching multiple actions
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文