redux-thaga

0.1.0 • Public • Published

redux-thaga Build Status

To not choose between redux-thunk and redux-saga

Installation

npm install --save redux-thaga

Integration

...
import * as sagas from './sagas'
import createThagaMiddleware from 'redux-thaga'
 
const thaga = createThagaMiddleware(sagas)
 
const createStoreWithMiddlewares = applyMiddleware(thaga)(createStore)
 
...

Usage

Like thunk for async actions

export const asyncActionCreator = () => (dispatch, getState) => {
    dispatch({
        type: `REQUEST`
    })
    
    request()
        .then(() => 
            dispatch({
                type: `SUCCESS`
            })
        )
}
 

Like saga

import {on} from 'redux-thaga'
 
export const onSomeAction = on(`SOME_ACTION_TYPE`, (dispatch, getState, action) => {
    request()
        .then(() => {
            dispatch({
                    type: `ANOTHER_ACTION_TYPE`
                })
        })
})
 

License

MIT

Package Sidebar

Install

npm i redux-thaga

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • galkinrost