ecommerce_sanity_stripe icon indicating copy to clipboard operation
ecommerce_sanity_stripe copied to clipboard

Fix for cart reordering while adding quantity.

Open ashharr opened this issue 2 years ago • 1 comments

Create a copy of the cartItems: const newCartItems = [...cartItems]; // for mutating the array in place

now we increase quantity, in the foundProduct and simply add it in the new array using index to prevent reordering.

    if(value === 'inc') {
      foundProduct.quantity += 1;
      newCartItems[index] = foundProduct;  // prevents reordering
      setCartItems(newCartItems)

ashharr avatar Jan 04 '23 09:01 ashharr

Very nice approach!

graphiiics avatar Jun 03 '23 17:06 graphiiics