Redux Saga vs Thunk: What should you choose?

  Рет қаралды 33,172

EdRoh

EdRoh

3 жыл бұрын

In this video, we compare and contrast Redux Saga and Thunk.
Helpful Links: / redux-middleware-the-d...
-----------
Subscribe to my channel: / @edrohdev
for more algorithm explanations, tech discussions, and programming tutorials!
-----------
Hey there, my name’s EdRoh. On my channel, you will find common coding algorithms and/or interview questions (with explanations of course). I also provide tutorials and courses on other programming topics in Web Development including Javascript, React, HTML, CSS, TypeScript, Redux, Node, Progressive Web Apps, React Native, Flutter, etc.
No matter what level you are, whether you are already in the software engineering field, or are just beginning coding in bootcamp or being self taught, my first and foremost desire is to help you provide with the best teaching content and learning resource I possibly can. As someone who understands the struggles of switching careers, I hope I can help guide you into this difficult but rewarding journey into engineering.

Пікірлер: 33
@KaranKumar-wb5bn
@KaranKumar-wb5bn 2 жыл бұрын
9:30 you said setting up thunk gets messy. I disagree, it's because you've not structured the code properly for thunk. You're using .then (instead of using async await)and explicit returns and also actions as functions. Instead you'd dispatch the object directly. You can make the code look really neat with thunk.
@abdelbariomymen7150
@abdelbariomymen7150 2 жыл бұрын
Yes, that's what I was thinking too
@ApprendreSansNecessite
@ApprendreSansNecessite 2 жыл бұрын
I mostly agree, but you are picking my attention with this: "... and also actions as functions. Instead you'd dispatch the object directly.". isn't redux-thunk all about using actions as functions? What am I missing? The problem I see with this code is that one "action" (`getUsersRequest`) is dispatching 2 other actions (`getUserFetch` -which by the way is a synonym of `getUsersRequest`, this is a red flag- and `getUserSuccess`). First of all, I think `getUsersRequest` is knowing too much about the rest of the system: we are not taking advantage of the decoupling that programming with actions allows. At no point is the system reacting to actions, the only thing that is abstracted is the CRUD operation on the store. Second: The code is lying in telling us `getUsersRequest` is an action. It is not. It doesn't need to be dispatched, it could just have been called from within the component (by passing `dispatch` as an argument): it's an overly complicated event handler. If you don't mind Karan, I would be interested to know how you would have written a clean thunk for this
@ankitkumar3037
@ankitkumar3037 2 жыл бұрын
that's excatly i was gonna write here buddy, i also have used multiple fetch requests many time with async or await
@marian_tsx
@marian_tsx 2 жыл бұрын
Yep, either that or using also RxJS Observables, it makes life way easier too.
@sandrosxila
@sandrosxila 2 жыл бұрын
Yes definitely, and if he wanted to avoid chaining or nesting, he could use async/await
@defnotathot
@defnotathot 2 жыл бұрын
Your videos are very enjoyable! I learned a lot of sagas with you, thanks man. I used to have the same thought that you said "uhhh gotta learn more stuff" - but with time that went away and now I appreciate sagas :)
@SouravDey55500
@SouravDey55500 2 жыл бұрын
Pretty clean tutorial!! Finally found a Saga / Thunk tutorial which explains things in a simple fashion.
@bagusamrullah4371
@bagusamrullah4371 2 жыл бұрын
Thank you for the clear explanation, I have been using Thunk this whole time and wanted to learn about Saga. I'm pretty comfortable using thunk, I feel like it's better in some cases. But knowing saga have plenty built in feature makes me reconsider it for my future project :D
@calwinstevepaul.k5376
@calwinstevepaul.k5376 2 жыл бұрын
Instead of using .then why can we use async await for avoiding callback hell??
@trevedhek4075
@trevedhek4075 2 жыл бұрын
The big advantage of Redux Saga seems to be the built-in helper functions/effects. Other than that, it is difficult to see why: > const response = yield call(fetch url); is an improvement over: > const response = await fetch(url); Also, for a better comparison, I'd like to see a solution that didn't use ANY middleware. It would be interesting to compare readability to thunks and sagas. I suspect it would look a lot like your thunk code.
@piotrekjazz1287
@piotrekjazz1287 2 жыл бұрын
A very good one. I watched it cause there are no other videos on this subject with a source code
@amitthakur5880
@amitthakur5880 2 жыл бұрын
Can't we use async await syntax for call back hell or dependency problem
@philippeb1039
@philippeb1039 2 жыл бұрын
Hm...so if we know how to use async await or Promise.all() then there is no need for saga right?
@roshanlalsahu7846
@roshanlalsahu7846 2 жыл бұрын
u can use async/await also right? what u did for saga
@nikhilev3840
@nikhilev3840 Жыл бұрын
On 11.0 you try to prove that consecutive api calls may create a callback hell hence use Saga. Can we use the async/await there?
@chaoliu2631
@chaoliu2631 2 жыл бұрын
Great explanation! Good job man.
@hamzaef5281
@hamzaef5281 2 жыл бұрын
Thank you!! great job 🙏🙏
@mohamedyoussef8835
@mohamedyoussef8835 2 жыл бұрын
Your videos are very enjoyable!
@codewithabhishek1676
@codewithabhishek1676 2 жыл бұрын
You can also use async and await for one line of code in case of redux thunk . And you can also use with axios. One more thing is your video is helpful for all , thanks for making such type of video 👍
@OscarRuiz-ql3bt
@OscarRuiz-ql3bt 2 жыл бұрын
I have a question maybe a little bit stupid, why can't we just use async await on a regular reducer and call again the reducer function if needed? why do we need to use a middleware? by the way great video
@Opacity5
@Opacity5 Жыл бұрын
cause reducer is a pure function?
@geebsayshi
@geebsayshi 2 жыл бұрын
I'm glad I'm not the only one who prefers saga. But you could have used asyn await for thunk to give it a better fight chance.
@madhousenetwork
@madhousenetwork 2 жыл бұрын
Thank you for this video
@joemurray1664
@joemurray1664 3 жыл бұрын
super helpful vid!
@AnNguyen-uv9yc
@AnNguyen-uv9yc 2 жыл бұрын
good tutorial, you made redux-sage very simple :3 😇😇😇
@netsaosa4973
@netsaosa4973 Жыл бұрын
isnt saga deprecated
@harmonhuynh
@harmonhuynh 2 жыл бұрын
ED ROHHHH!!!
@priyanshrawal1144
@priyanshrawal1144 Жыл бұрын
great video
@pujamaity9403
@pujamaity9403 2 жыл бұрын
Nice video
@lvendrame
@lvendrame 2 жыл бұрын
Promise comes to avoid callback hell, then you start a promise hell, why? Just return the new promise and use its return in the next then.
@stencil25
@stencil25 2 жыл бұрын
I believe that an engineer would benefit more by; - using Thunks with async/await (avoiding callback hell), - applying any async effects themselves (e.g. Throttling). This could include using a lower level lib such as RxJS - which can be applied to more situations, outside of state management. As an engineers, learning how to handle async events is crucial to personal development, and will pay off in the long run.
Understanding Redux Saga with a simple API call Tutorial
19:12
Redux is Easy | Explanation Tutorial
9:22
EdRoh
Рет қаралды 11 М.
100❤️
00:19
MY💝No War🤝
Рет қаралды 23 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 125 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 23 МЛН
Redux Saga Example - React Notes Taking App. Redux Saga vs Thunks
9:25
Learn React #13 - Introduction to Redux Saga and getting data from APIs
35:21
Redux Middleware/Async/Thunk: The complete Guide
1:06:03
Sanjeev Thiyagarajan
Рет қаралды 48 М.
Redux Sagas vs Redux Toolkit Query
22:58
Jack Herrington
Рет қаралды 34 М.
GPT4o Mini - Lightning Fast, Dirty Cheap, Insane Quality (Tested)
13:20
Телефон-електрошокер
0:43
RICARDO 2.0
Рет қаралды 1,3 МЛН
Как правильно выключать звук на телефоне?
0:17
Люди.Идеи, общественная организация
Рет қаралды 1,8 МЛН
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН