Skip to content

Instantly share code, notes, and snippets.

@timbuckley
Created September 6, 2016 16:03
Show Gist options
  • Save timbuckley/a74161fb641e8e6da0d35fe5b12c78de to your computer and use it in GitHub Desktop.
Save timbuckley/a74161fb641e8e6da0d35fe5b12c78de to your computer and use it in GitHub Desktop.
function itemsReducer(state, action) {
switch(action.type) {
case 'UPDATE_ITEM':
return state.items.map(i => itemReducer(i, action))
default:
return state
}
}
function itemReducer(state, action) {
switch(action.type) {
case 'UPDATE_ITEM':
return {
...state,
[action.payload.fieldToChange]: action.payload.newValue
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment