Which is better Redux- Thunk Or Redux-Saga

Which is better Redux- Thunk Or Redux-Saga


Being a Frontend Developer it is not easy to select which of them is good to use. Even I face challenges when I have to select for the first time, so here is my experience of how I select each of them for my projects

So let’s begin with an understanding of Redux

It is an open-source JavaScript library for managing and centralizing the application state. It is most commonly used with such as React or Angular for building user interfaces.

Now, what is Redux-Thunk and Redux-Saga?

It is a middleware or simply called an async function which is generally used for calling API and storing response data in redux store to remove side effects.

So What’s the difference between them?

So let first start with Redux-Thunk:

It is a middleware that allows you to call the action creators that return an async function(thunk) which takes the store’s dispatch method as the argument which afterward is used to dispatch response of Api in redux store so side effects have been finished.

Let’s jump into code for better understanding.

Here is the example of how actions creators and thunk functions are written

Redux-Saga:

It is also a middleware library that helps us with API calls or side effects. It uses an ES6 feature called ‘Generators’ which helps us to write asynchronous code.

Generators are the functions that came with ECMA Script 6. And the amazing part is that the generator functions can be paused between the execution or can even be exited and later re-entered.

To understand redux-saga better we need to compare simple async function with ECMA Script 6 generator function

Redux Saga listens to the dispatched actions and triggers an API call or any other side effect you write.

It is completely up to you to choose the right approach for your projects. I have used both Redux-Thunk and Redux-Saga, and I feel if you are working on a small or a medium scale project, you can choose Redux-Thunk. It will work like a charm. But on the other hand, for bigger projects, Redux-Thunk may sometimes get you in trouble, as it can be hard to scale if your side effect or asynchronous logic increases, whereas in the case of Redux-Saga, it comes power-packed with some amazing things such as concurrent side effects, canceling side effects, debouncing and is easy to scale.

To be honest, I love both tools. Choosing one is difficult as both have their advantages and disadvantages.

Overall Difference:

So what you are looking for is to jump the projects and start implementing them.

The further official link for more explanation:

https://redux.js.org/usage/writing-logic-thunks

https://redux-saga.js.org/docs/introduction/GettingStarted


Reset Engineering

Software Engineer at NA

2 年

Like most article flooded on the internet, this one also "jumps to code". Explaining flow or syntax doesn't covers the "versus". What people look for is the philosophy of the two and when to use what.

回复

要查看或添加评论,请登录

Vnurture Technologies的更多文章

  • Evolving OTT Platforms with Blockchain Technology

    Evolving OTT Platforms with Blockchain Technology

  • Future Scope of Power BI

    Future Scope of Power BI

    The Art of Visualization – is a way of clarifying what it is you want to manifest in your life/business/, bringing it…

  • Django: An informative Blog

    Django: An informative Blog

    What is Django? This is the common question for newbie as well as experienced developers: what Django actually is? So…

  • Kubernetes

    Kubernetes

    commonly stylized as K8s(no. Of characters between K and S is 8) is an open-source container-orchestration system for…

  • JavaScript Framework

    JavaScript Framework

    What Makes JavaScript So Popular? Our lives today are dependent on the interactivity that JavaScript provides. If you…

  • React Meetup

    React Meetup

    https://www.meetup.

  • Checklist for UI developer

    Checklist for UI developer

    ? Use ALT tags for all graphics, especially navigation graphics. ? Use black text on white background whenever possible…

  • Technical Advancement Program

    Technical Advancement Program

    In this competitive world of software technology, it is very imperative that you are on top and current on what you do…

  • Tally readiness programs

    Tally readiness programs

    1) For Professional and 2) For corporate For Professional Based upon our own research and to help fresh…

  • Youth Tech Program

    Youth Tech Program

    Youth is India’s future knowledge pool and they are the future of our country. VNurture believe that nurturing starting…

社区洞察

其他会员也浏览了