Skip to content

Instantly share code, notes, and snippets.

@ericorruption
Created November 1, 2017 08:08
Show Gist options
  • Save ericorruption/023e2c8b81f998dd177c6676f69b968f to your computer and use it in GitHub Desktop.
Save ericorruption/023e2c8b81f998dd177c6676f69b968f to your computer and use it in GitHub Desktop.
Redux: Avoiding mutation on state change
const toggleObjectBoolean = object => {
...object,
bool: !object.bool
}
const addToList = list => [
...list,
'new item'
]
const removeFromList = (list, index) => [
...list.slice(0, index),
...list.slice(index + 1)
]
const incrementInList = (list, index) => [
...list.slice(0, index),
list[index] + 1
...list.slice(index + 1)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment