SolidJSS
SolidJSโ€ข3y agoโ€ข
1 reply
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" }


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
    })
},


the screenshot shows the modified, and original object.

Why could this be happening?
image.png
Was this page helpful?