hake-redux
v1.0.0
Published
A promise middleware for redux
Downloads
7
Readme
hake-redux
A promise middleware for redux, based on https://github.com/lelandrichardson/redux-pack
Install
$ npm install --save hake-redux
# or
$ yarn add hake-redux
Usage
import { createStore, applyMiddleware } from 'redux'
import hakeReduxMiddleware from 'hake-redux'
import rootReducer from './reducer'
// axios is a xhr lib just like fetch.
import axios from 'axios'
// your client
const client = axios.create()
// store
const store = createStore(
rootReducer,
applyMiddleware(hakeReduxMiddleware(client))
)
API
The difference between redux-pack and hake-redux is :
// actions.js
export function loadFoo(id) {
return {
type: LOAD_FOO,
// redux-pack way
// promise: Api.getFoo(id),
// hake-redux doing.
promise: client => client.get('/path/to/foo')
meta: {
onSuccess: (response) => logSuccess(response)
},
};
}
License
MIT © bang lelandrichardson