redux-actions-helper
helper for redux-actions
Installation
npm install redux-actions-helper --save
createAction
-
payloadCreator:
(args) => payload
default:
(...args) => args
-
metaCreator:
(args) => payload
default:
(...args) => args
// actions/todo.js ; const toggleTODO = ; const updateTODO = ; // you can get action name by name attribute or toString method// toggleTODO.actionName is equal 'TOGGLE_TODO' // toggleTODO.toString() is equal 'TOGGLE_TODO'
mapToAction then use it
// app/Home.js thisprops thisprops
listenActions
// reducer/todo.js; const initState = tasks: { } initState // ==== you also can use handleActions , is same
async
add promise-middleware to middlewares
;
// actions/todo.js; const updateTODO = ;
// reducer/todo.js; const initState = tasks: //handleActions //listenActions { on on} initState
createThunkAction
if you use thunk middleware, you can use createThunkAction
// actions/todo.js; const updateTODO = ;
use it as same as createAction createThunkAction will auto create 'pending, success, fail' action.
// app/Home.js thisprops