create-async-action

1.0.1 • Public • Published

create-async-action

wrapper for redux-actions createAction function for better work with redux-promise-middleware

When using redux-actions and redux-promise-middleware together its annoying to do something like this:

const myAction = createAction('MY_ACTION', async () => {
  ...
});
 
const reducer = handleActions({
  [myAction + '_SUCCESS']: () => ...
  [myAction + '_ERROR']: () => ...
  [myAction + '_LOADING']: () => ...
}, { ... })

Instead of this you can do something like this:

import createAsyncAction from 'create-async-action';
 
const myAction = createAsyncAction('MY_ACTION', async () => {
  // the same code as before
});
 
const reducer = handleActions({
  [myAction.success]: () => ...
  [myAction.error]: () => ...
  [myAction.loading]: () => ...
}, { ... })

Yes, here I use custom suffixes for redux-promise-middleware.

Thanks for inspiring, matpaul

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    3
  • 1.0.0
    1

Package Sidebar

Install

npm i create-async-action

Weekly Downloads

4

Version

1.0.1

License

MIT

Last publish

Collaborators

  • iamolegga