Last active
November 25, 2015 21:57
-
-
Save rohn/b41c954ef9f2b91710e3 to your computer and use it in GitHub Desktop.
destructuring nested objects with value changes
This file contains 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 state = {a:1, b:2, c:3, d:{aa:11, bb:22}} | |
console.log(state) // { a: 1, b: 2, c: 3, d: { aa: 11, bb: 22 } } | |
const b = 55 | |
const aa = 444 | |
const total = {...state, b, d: {...state.d, aa}} | |
console.log(total) // { a: 1, b: 55, c: 3, d: { aa: 444, bb: 22 } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this will be useful for the redux pattern of reducers and returning new state