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...
Use Thunk instead of Saga for simple and trivial tasks like:
Use Saga for
Preferring saga over thunk or the other way round lies depends on the task in hand. Both have their fair share of trade-offs.
Thunks dispatch a function that in turn dispatches an actions. So,
Sagas use generator functions underneath so the function virtually pauses at an async action and resumes when it is resolved
Both thunk are saga are used as middle ware for redux used usually for api hit. Thunk is very easy to used compared to saga, but saga has alot of benefits over thunk for example saga has effect takeLatest
which would be effective if user is pressing button repeatedly, thunk would make api hit on every click but using saga effect only latest(one) api hit will be made. It also have other effect and there benefits but it has learning overhead
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