A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.
npm install --save dispatch-wrapper
const wrapper = require('dispatch-wrapper');
// Dispatch an action
let Fetcher = (api, dispatch) => {
wrapper(api, (data) => {
dispatch({
type: FETCH,
payload: data
});
});
}
// Action creators using `redux-thunk`
let fetch_data = (api) => {
return (dispatch) => {
return Fetcher(api, dispatch);
}
}
See the complete example here
The wrapper method to dispatch the payload
Any JSON api
Type: string
A callback function
npm run test
Add unit test for any new or changed functionality
ISC