3imuyw
Last Updated: December 23, 2016
·
230
· iondrimba
178548

Redux action creator generator (ES6)

const createAction = (type, ...args) => {
    let action = { type };
    action = Object.assign({}, action, ...args);
    return action;
};
export default createAction;

Usage

dispatch(createAction('actionName', { data1, data1 }));

For simple values

dispatch(createAction('actionName', { text:'Hello' }));
dispatch(createAction('actionName', { value:false }));
Say Thanks
Respond