1.0.1 • Published 7 years ago

create-async-action v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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