S
SolidJS•13mo ago
Mr Void

Unable to edit data in store ( Solved )

I have a store function that is meant to update some of the properties of an existing collection within an array of collections. I am trying to update the properties using the Object.assign method:
let collection = { title: "original title", color: "yellow" } // assume > original object
let data = { color: "red" } // assume > new data to update original object

let c = Object.assign({}, collection, data)
// c => { title: "original title", color: "red" }
let collection = { title: "original title", color: "yellow" } // assume > original object
let data = { color: "red" } // assume > new data to update original object

let c = Object.assign({}, collection, data)
// c => { title: "original title", color: "red" }
However, within the following code section, the collection object does not update within the array itself after being returned from the map function:
updateCollection: (collectionId: string, data: Partial<NoteCollection>) => {
setState("notes", "collections", (collections: NoteCollection[]) => {
const tempCollections = [...collections]

tempCollections.map(collection => {
if (collection.id !== collectionId) {
return collection
}

const newCollection = Object.assign({}, {...collection}, data);
console.log('collection found ', newCollection)
return newCollection
})

console.log(tempCollections)
return tempCollections
})
},
updateCollection: (collectionId: string, data: Partial<NoteCollection>) => {
setState("notes", "collections", (collections: NoteCollection[]) => {
const tempCollections = [...collections]

tempCollections.map(collection => {
if (collection.id !== collectionId) {
return collection
}

const newCollection = Object.assign({}, {...collection}, data);
console.log('collection found ', newCollection)
return newCollection
})

console.log(tempCollections)
return tempCollections
})
},
the screenshot shows the modified, and original object. Why could this be happening?
No description
1 Reply
Mr Void
Mr VoidOP•13mo ago
Good lord peporestless all I needed to do was return the result of map function 😩 https://stackoverflow.com/a/42242325/6212957
Want results from more Discord servers?
Add your server