Instantly share code, notes, and snippets.

Embed
What would you like to do?
example creating and updating an object store
# Copying and Updating Store
var a = {name : "chris"}
var postState = {posts: null }
var userState = {name : null }
var store = {postState, userState}
console.log("store: ", store)
// initial state
//console.log(store)
// Updataed state
// first, userState = {copy previous userState key, update the userState key in store}
userState = {...store.userState, ...a}
// second, store={copy previous store, updated store}
store = {...store, userState}
console.log(store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment