Miss any of our Open RFC calls?Watch the recordings here! »

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

Install

npm i create-async-action

DownloadsWeekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • avatar