✕
Forbes India Leader Recognition
e.preventDefault(); // Prevent form submission input.blur(); // remove focus input.value = ""; // optional: clear the input

Why React Saga is better then Thunk?

Why React Saga is better then Thunk?

Featured Image

Tudip

What is Redux?

Redux is basically a state management library for javascript applications and is mainly used with React JS and is also familiar as predictable state container. In React, data flows from parent component to child component in the form of props.

In react mostly everything is component, so if there are too many number of components, here comes the role of redux as it manages the states of all components.

The key points of interest while working with redux are “Action”, “Dispatcher” and “Reducer”.
Action is something which triggers what needs to be done from the component dispatcher collects the action that is actively triggered and pasess it to reducer. Now reducer is responsible what needs to be done to update the store data.

Middleware

Middleware is block of code which acts as a mediater while the process of receiving a request or generating response. Here we are going to discuss about the 2 most popular libraries redux-thunk and redux-saga.

A thunk is a function that acts as a wrapper in which it wraps an expression to delay its evaluation. Thunk allows to write an action creators that return a function instead of the typical action object.

Where as redux-saga is a library that mainly focuses on easy handling of application side effects and more efficient for execution.

Redux-thunk

Thunk is a function which optionaly takes some parameters and returns another function, it takes dispatch and getState functions and both of these are supplied by Redux Thunk middleware.

Here is the basic structure of Redux-thunk

export const thunkName = parameters => (dispatch, getState) => {
// You can write your application logic here
};

Example:

import axios from "axios";
import GET_LIST_API_URL from "../config";

const fetchList = () => {
return (dispatch) => {
axios.get(GET_LIST_API_URL)
.then((responseData) => {
dispatch(getList(responseData.list));
})
.catch((error) => {
console.log(error.message);
});
};
};

const getList = (payload) => {
return {
type: "GET_LIST",
payload
};
}

export {
fetchList
}

Redux-saga

It allows one to express complex logic functions as pure functions called sagas. From a testing point of view, pure functions are desirable because they are predictable and repeatable, making them relatively easy to test. Sagas are implemented by special functions called functions of the generator. These are an ES6 JavaScript new feature. Basically, everywhere you see a yield statement, execution jumps in and out of a generator. Think of a statement of yield as causing the generator to pause and return the value of yield. The caller can then resume the generator after the yield at the statement.

Example:

import axios from "axios";
import GET_LIST_API_URL from "../config";
import {call, put} from "redux-saga/effects";

const fetchList = () => {
return axios.get(GET_LIST_API_URL);
}

function *fetchList () {
try {
const responseData = yield call(getCharacters);
yield put({type: "GET_LIST", payload: responseData.list});
} catch (error) {
console.log(error.message);
}

}

export {
fetchList
};

Conclusion

You might think that syntax is the biggest difference. Although it is true that thunks and sagas are quite different in writing and reasoning, there is something bigger. In response to an action, Thunks can never act. On the other hand, Redux-Saga subscribes to the store and can trigger a saga when some action is dispatched to run or continue.
From the above examples it is clear that react saga is a bit handy to use over react-thunk.

Related Posts

Latest Posts

  • All Posts
  • AI Powered Knowledge
  • ai/ml
  • CEO India Magazine
  • CMMI level 5 Certification
  • e-learning
  • Fintech
  • gaming
  • Generative AI
  • healthcare
  • manufacturing
  • News
  • OTT
  • Portfolio
  • supply chain
  • travel and hospitality
  • Tudip's AI Hackathon
  • Voxlearn Enterprises
    •   Back
    • Android
    • iOS
    • Java
    • PHP
    • MEAN
    • Ruby
    • DotNet
    • IoT
    • Cloud
    • Testing
    • Roku
    • CMS
    • Python
Artificial Intelligence in Healthcare

Artificial Intelligence in Healthcare

September 23, 2026

Explore how artificial intelligence in healthcare is transforming clinical decision-making, and patient care .

Read More
AI in Manufacturing: Machine Intelligence  Meets Industrial Innovation

AI in Manufacturing: Machine Intelligence Meets Industrial Innovation

September 23, 2026

Explore how AI is transforming manufacturing through predictive maintenance, intelligent quality control, data-driven operations.

Read More
Artificial Intelligence in Manufacturing: Enabling Intelligent, Flexible and Cost-Effective Production Through AI

Artificial Intelligence in Manufacturing: Enabling Intelligent, Flexible and Cost-Effective Production Through AI

September 23, 2026

Discover how AI is transforming manufacturing through intelligent automation.

Read More

India

Plot No. 11/2, Phase 3, Hinjewadi Rajiv Gandhi Infotech Park, Pune, India – 411057.
info@tudip.com
+91-96-8990-0537

United States

1999 S. Bascom Ave Suite 700, Campbell CA. 95008, USA.
info@tudip.com
+1-408-216-8162

Canada

64 Caracas Road North York, Toronto Ontario M2K 1B1, Canada.
info@tudip.com

Mexico

Calle Amado Nervo #785 Interior B Colonia Ladron De Guevara 44600 Guadalajara, Jalisco, Mexico.
info@tudip.com

Singapore

77 High Street, #10-12B High Street Plaza, Singapore 179433.
info@tudip.com

Colombia

Cra. 9 # 113-53 Of. 1405 Bogotá D.C., Colombia.
info@tudip.com

UAE

Tudip Information Technologies L.L.C Office No 109, ABU HAIL BUILDING 13, Abu Hail, Dubai, UAE.
info@tudip.com

Nigeria

22 Kumasi Crescent, Wuse 2, Abuja, Nigeria.
info@tudip.com