redux-thunk-action-helpers
v1.0.1
Published
redux helpers for thunk action and action creators
Downloads
3
Maintainers
Readme
Installation
install
$ npm i redux-thunk-action-helpers
$ yarn add redux-thunk-action-helpers
Motivation
Thunk actions usually follow the same rules. Dispatch start action, run some code, dispatch the result on the sucess action or dispatch the error on the fail action
Example
action types
import { createActionTypes } from 'redux-thunk-action-helpers';
export const userActionTypes = createActionTypes('my-app', 'FETCH', 'SUBMIT');
/*
* userActionTypes = {
* FETCH : '@@my-app/FETCH',
* FETCH_START : '@@my-app/FETCH_START',
* FETCH_SUCCESS : '@@my-app/FETCH_SUCCESS',
* FETCH_ERROR : '@@my-app/FETCH_ERROR',
* SUBMIT : '@@my-app/SUBMIT',
* SUBMIT_START : '@@my-app/SUBMIT_START',
* SUBMIT_SUCCESS : '@@my-app/SUBMIT_SUCCESS',
* SUBMIT_ERROR : '@@my-app/SUBMIT_ERROR',
* }
*/
action creator
import { createActionCreator } from 'redux-thunk-action-helpers';
export const doFetchUsers = createActionCreator('GET_USERS', (page, limit) => api.getUsers(page, limit));
API
createActionTypes(namespace, ...types);
createActionCreator(type, fn);
fn = (...args, { dispatch, getState, extra }) => Promise/Value
License
MIT