https://github.com/nitin42/dispatch-wrapper
A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.
https://github.com/nitin42/dispatch-wrapper
dispatch react redux redux-thunk wrapper
Last synced: 10 months ago
JSON representation
A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.
- Host: GitHub
- URL: https://github.com/nitin42/dispatch-wrapper
- Owner: nitin42
- Created: 2017-02-01T17:40:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-02T12:30:30.000Z (almost 9 years ago)
- Last Synced: 2025-01-12T23:11:24.122Z (12 months ago)
- Topics: dispatch, react, redux, redux-thunk, wrapper
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dispatch-wrapper
[](https://travis-ci.org/nitin42/dispatch-wrapper)
> A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.
## Install
```
npm install --save dispatch-wrapper
```
## Usage
```javascript
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](https://github.com/nitin42/dispatch-wrapper/blob/master/example.js)
## API
#### wrapper(api, cb)
The wrapper method to dispatch the payload
##### api
Any JSON api
Type: `string`
##### cb
A callback function
## Test
```
npm run test
```
## Contributing
Add unit test for any new or changed functionality
## License
ISC