i've tried to watch many videos about redux saga and rtk query but still can't choose,so please can any body help me with that, like when better use saga and rtk query,and which one is the best now?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With