redux-saga-takeuntil
v0.1.1
Published
A utility to start a saga when a particular action is dispatched, and then cancel it when another action is dispatched
Downloads
5
Readme
Redux Saga takeUntil
Redux-Saga takeUntil is a utility that is useful if you wish to start a saga when a particular action is dispatched, and then cancel it when another action is dispatched.
Consider the scenario when you have some saga functions which you would only like to be run following a particular action being dispatched, but only until another action is dispatched. Example scenarios include:
- When a user navigates to a page, run some sagas. Stop them when the user navigates elsewhere.
- When a form is created, run some sagas related to the form. Stop them when the form is destroyed.
Usage
npm install --save redux-saga-takeuntil
import { takeUntil } from 'redux-saga-takeuntil
- In a saga, invoke takeUntil, passing:
- a
String
identifying the action which will START your saga. - a
String
identifying the action which will STOP your saga. - a Generator
Function
which will be invoked on the START action. This generator may itselfyield
further sagas, creating a "tree" of sagas which are brought into scope on your START action, and cancelled and taken out of scope when the STOP action is dispatched.
- a
For a full example, built with create-react-app
, checkout the demo
branch.