Skip to content

A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.

Notifications You must be signed in to change notification settings

nitin42/dispatch-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dispatch-wrapper

Build Status

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

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

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

About

A wrapper which makes it easy to dispatch the payload received from a JSON api in your action creators.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published