Created
April 27, 2020 16:10
-
-
Save weeksie/fbbfa32555bb9922e011b35865850ccf to your computer and use it in GitHub Desktop.
Utility function for creating Redux actions. Used like so:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { camelCase } from 'camel-case'; | |
export function createActions(actionTypes) { | |
const types = {}; | |
const actions = {}; | |
actionTypes.forEach(property => { | |
types[property.replace('/', '_')] = property; | |
actions[camelCase(property)] = x => ({ type: property, payload: x }); | |
}); | |
return { types, actions }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment