RTK Query is a single-purpose tool to manage api caching logic for you.
Redux Saga is an orchestration tool that allows you to do pretty much anything - but you have to write it yourself. And that might mean a lot of code to write.
So the base question is "do I need something to trigger an api" or "do I want to write code myself to do something". After that you get the question is Redux Saga is a good idea at all - and most of the time, it isn't. Redux Saga is a power tool with a lot of functionality - that also adds a lot of complexity. The recommendation from the Redux Style Guide is to use the most simple tool for every job: Use Redux Thunk for async logic. If you are one of the 10% apps that needs "reactive logic", use the RTK listener middleware (only for those things, stay with thunks for the simple stuff!). Only if you belong to those 1% of apps that needs something that is actually not possible with those two much more simple tools, use saga. And even then, mix it with thunks.
发布评论
评论(1)
他们甚至没有做同样的事情。
RTK查询是一种为您管理API缓存逻辑的单点工具。
Redux Saga是一种编排工具,可让您几乎做任何事情 - 但是您必须自己写。这可能意味着要编写很多代码。
因此,基本问题是“我需要一些东西来触发API”或“我想自己写代码来做某事”。 在之后,您得到的问题是Redux Saga根本是一个好主意 - 大多数时候,不是。 Redux Saga是一种具有很多功能的动力工具 - 还增加了很多复杂性。 redux样式指南的建议是每项工作的最简单工具:使用redux thunk作为异步逻辑。如果您是需要“反应性逻辑”的10%应用程序之一,请使用RTK (仅适用于这些东西,请与简单的东西呆在一起!)。只有当您属于那两个更简单的工具实际上不可能使用的应用程序的1%的应用程序时,请使用SAGA。即使那样,它也将其与thunks混合。
They are not even doing the same thing.
RTK Query is a single-purpose tool to manage api caching logic for you.
Redux Saga is an orchestration tool that allows you to do pretty much anything - but you have to write it yourself. And that might mean a lot of code to write.
So the base question is "do I need something to trigger an api" or "do I want to write code myself to do something". After that you get the question is Redux Saga is a good idea at all - and most of the time, it isn't. Redux Saga is a power tool with a lot of functionality - that also adds a lot of complexity. The recommendation from the Redux Style Guide is to use the most simple tool for every job: Use Redux Thunk for async logic. If you are one of the 10% apps that needs "reactive logic", use the RTK listener middleware (only for those things, stay with thunks for the simple stuff!). Only if you belong to those 1% of apps that needs something that is actually not possible with those two much more simple tools, use saga. And even then, mix it with thunks.