Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the difference between redux thunk and redux saga?


Asked by Kristopher Roberson on Dec 10, 2021 FAQ



However, unlike Redux-Thunk, which utilizes callback functions, a Redux-Saga thread can be started, paused and cancelled from the main application with normal Redux actions. Like Redux-Thunk, Redux-Saga has access to the full Redux application state and it can dispatch Redux actions as well.
In addition,
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.
Just so, Its concept is pretty straight forward: while Redux only allows you to dispatch plain action objects, Redux-Thunk also allows you to dispatch functions. This enables us to encapsulate additional logic as well as asynchronous operations and respond by dispatching different actions.
And,
react-redux - bindings between redux and react, that creates containers (smart components) that listen to the store's state changes, prepare the props for and rerender the presentational (dumb) components. redux-thunk - middleware that allows you to write action creators that return a function instead of an action.
In respect to this,
The saga middleware exposes a set of helper functions to create declarative effects (plain javascript objects) that can be yielded by our sagas. The middleware will then handle the objects yielded behind the scenes. The call () -helper for example lets us yield effects describing a function and its arguments to Redux-Saga.