Created
November 1, 2017 08:08
-
-
Save ericorruption/023e2c8b81f998dd177c6676f69b968f to your computer and use it in GitHub Desktop.
Redux: Avoiding mutation on state change
This file contains hidden or 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
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