redux-promise-utils
v1.0.4
Published
redux promise utils for you!
Downloads
5
Readme
redux-promise-utils
Based on redux-thunk & redux-actions.
Easy utils to handle Promise in redux.
Quick Start
Install
use npm
npm i redux-promise-utils --save
use yarn
yarn add redux-promise-utils
Usage
- Ensure your reducer is handled by
redux-thunk
. - Ensure your api is a Promise.
// data/action.js
import { createPromiseAction } from 'redux-promise-utils'
import * as api from './api'
export const fetchAction = createPromiseAction('fetchList', api.fetchList)
// data/reducer.js
import { createReducer } from 'redux-promise-utils'
import { fetchAction } from './action'
const initState = {}
const reducer = createReducer(initState)
// catch sync action
.which('SYNC_ACTION', (state, action) => {
return state
})
// catch async action with three state
.asyncWhich(fetchAction, {
start(state, action) {
return state
},
success(state, action) {
return state
},
fail(state, action) {
return state
}
})
// build redux reducer handler
.build()
export default reducer