Redux-Saga is a redux middleware which aims to make application side effects(i.e. Asynchronous data fetching and accessing the browser cache) easier to manage, more effective to execute, and better handling failures.
In this article, I would like to share Redux-Saga information for beginners.
๐ Installation
yarn add redux-saga |
๐ Beginner Tutorial
We are going to use the trivial counter demo from the Redux tutorial repository.
The application is quite simple but is a good fit to illustrate the basic concepts of redux-saga.
Initial Setup
In the command line, run:
# clone tutorial repository |
๐ฐ Hello Sagas!
There are two buttons: Increment
and Decrement
a counter. From now on, we will add Async Increment
button to increament the counter 1 seconde after your click and a callback onIncrementAsync
.
Create a file sagas.js
then add the folling snippet:
import { delay } from 'redux-saga'; |
We will make the changes to main.js
:
import "babel-polyfill" |
Weโll provide an additional button and a callback onIcrementAsync
to Counter.js
:
import React, { Component, PropTypes } from 'react' |
๐ฃ More Detail
If you want to know more detail information, please see official document Beginner Tutorial ยท Redux-Saga.
In the document, It are described for concept, how to write Unit Test for redux-saga or some other kindness information to use.
๐ฅ Recommended VPS Service
VULTR provides high performance cloud compute environment for you.
Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour).
In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!