Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Piliponful/d71a6f280167e4cf71d8b527bc6d78e8 to your computer and use it in GitHub Desktop.
Save Piliponful/d71a6f280167e4cf71d8b527bc6d78e8 to your computer and use it in GitHub Desktop.
redux abstruction
export default initialState => {
const stateEntriesNames = Object.keys(initialState)
const reducer = (state, action) => stateEntriesNames.includes(action.type) ? ({ ...new Map(state).set(action.type, action.payload) }) : initialState
const setters = stateEntriesNames.reduce((acc, next) => ({ ...acc, [next]: payload => ({ type: next, payload }) }), {})
return { reducer, setters }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment