Skip to content

Instantly share code, notes, and snippets.

@rohn
Last active November 25, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohn/b41c954ef9f2b91710e3 to your computer and use it in GitHub Desktop.
Save rohn/b41c954ef9f2b91710e3 to your computer and use it in GitHub Desktop.
destructuring nested objects with value changes
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 } }
@rohn
Copy link
Author

rohn commented Nov 25, 2015

this will be useful for the redux pattern of reducers and returning new state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment