I am stuck with a problem where I am updating React state with an array of objects where my original object is like this.
[{id:"123", name:"Product 1"}, {id:"456", name:"Product 2"}];
Suppose this is an e-commerce cart list, where now if I add the same product again, being 'id' property as unique for each product it should increase the quantity of that product.
I need this [[{id:"123", name:"Product 1 , quantity: 2"}, {id:"456", name:"Product 2"}];]
Instead I am getting state like this,
[{id:"123", name:"Product 1"}, {id:"456", name:"Product 2"},{id:"123", name:"Product 1"} ];
I do not want that third item on my array, I want it to increase the quantity property which is also not available on the object before.
I am using React hooks on this
Please do help. Thanks in advance.