Skip to content

Instantly share code, notes, and snippets.

@weeksie
Created April 27, 2020 16:10
Show Gist options
  • Save weeksie/fbbfa32555bb9922e011b35865850ccf to your computer and use it in GitHub Desktop.
Save weeksie/fbbfa32555bb9922e011b35865850ccf to your computer and use it in GitHub Desktop.
Utility function for creating Redux actions. Used like so:
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