12-03-2017
Redux saga is a redux middleware library that is designed to simplify, make more efficient and easier to test the handling of side effects and network requests in your redux app.
Redux-Saga is a middleware which means that it can be started, paused and cancelled from the main application with normal redux actions. It can dispatch redux actions and has access to the full redux application state.
It uses a new ES6 feature called ‘Generators’ that allows us to write asynchronous code that looks synchronous and is easy to test.
This seems to be the currently preferred library to what was commonly used before: redux-thunk. As it states in the docs; with redux-saga ‘you don’t end up in callback hell, you can test your asynchronous flows easily and your actions stay pure.’
With react-thunk it was required to return a function and deal with a promise chain. Instead with redux-saga we write a simple try/catch block to catch any errors involved with request and use ‘put’ to dispatch an action to notify our reducers.
Install:
$ yarn add redux-saga