score:1

Accepted answer

try this:

setauthenticateduser({ ...authenticateduser, shoppingcart:[{...authenticateduser.shoppingcart[0],products:['newitem']}] })

score:0

const authenticatedusercopy = { ...authenticateduser }
authenticatedusercopy.shoppingcart[0].products = ['new product']
setauthenticateduser(authenticatedusercopy)

score:0

{ 
    ...authenticateduser,
    shoppingcart: authenticateduser.shoppingcart.map(s => { //map all items
        return {
            ...s,
            products: [...s.products, 'new item'] //add item
        }
    })
}

Related Query

More Query from same tag