Skip to content

Commit 5bb4648

Browse files
committed
Refactor
1 parent d4d51d1 commit 5bb4648

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/components/Cart/CartContents.component.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,8 @@ const CartContents = () => {
3535
const [updateCart] = useMutation(UPDATE_CART);
3636

3737
const handleRemoveProductClick = (cartKey: string) => {
38-
// Optimistically update local state
39-
if (cart) {
40-
const updatedProducts = cart.products.filter((p: Product) => p.cartKey !== cartKey);
41-
const removedProduct = cart.products.find((p: Product) => p.cartKey === cartKey);
42-
const qtyRemoved = removedProduct?.qty || 0;
43-
44-
setCart({
45-
...cart,
46-
products: updatedProducts,
47-
totalProductsCount: cart.totalProductsCount - qtyRemoved
48-
});
49-
}
38+
// Update local state
39+
useCartStore.getState().removeProduct(cartKey);
5040

5141
// Update remote state in background
5242
updateCart({

0 commit comments

Comments
 (0)