Last Updated: December 23, 2016
·
1.383K
· iondrimba

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 }));

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

A React app still loads third-party scripts outside the component tree. Tag managers, analytics, and payment fields can read the DOM those components render.

Security insights from Cside