adrianhajdin / ecommerce_sanity_stripe

Modern Full Stack ECommerce Application with Stripe
https://jsmastery.pro
2.19k stars 675 forks source link

Fix cart items reordering using Array.map transform #87

Open niranad opened 1 year ago

niranad commented 1 year ago

toggleCartItemQuantity function in stateContext

Reordering of cart products is due to filtering the cart items to remove the found product followed by appending the mutated found product to the end of the cart. Instead, simply mapping over the items and returning an updated item for the specific item we are searching would preserve the order.