From fe775637414c6da523882d4f96d6613173e5ccb8 Mon Sep 17 00:00:00 2001 From: Alex Tran Date: Tue, 29 Nov 2022 00:35:05 +1100 Subject: [PATCH 1/2] fixed subtotal --- package-lock.json | 1 + src/Components/Cart.jsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index d01ddfa..bbd664e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,6 +5,7 @@ "requires": true, "packages": { "": { + "name": "react-ecommerce", "version": "0.0.1", "dependencies": { "@headlessui/react": "^1.6.0", diff --git a/src/Components/Cart.jsx b/src/Components/Cart.jsx index 917b7a1..18d0c34 100644 --- a/src/Components/Cart.jsx +++ b/src/Components/Cart.jsx @@ -3,6 +3,10 @@ import { XIcon } from "@heroicons/react/outline"; import React, { Fragment } from "react"; export default function Cart({ open, setOpen, cart, updateCart }) { + var subtotal = 0; + cart.forEach(product => { + subtotal += product.price + }) return (

Subtotal

-

$262.00

+

{subtotal}

Shipping and taxes calculated at checkout.

From 8cafa29d5442a4830fdaaa4685063979ef477aff Mon Sep 17 00:00:00 2001 From: Alex Tran Date: Tue, 29 Nov 2022 00:43:19 +1100 Subject: [PATCH 2/2] fixed infinite loop --- src/Components/ProductTable.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/ProductTable.jsx b/src/Components/ProductTable.jsx index ea76621..08d0dcf 100644 --- a/src/Components/ProductTable.jsx +++ b/src/Components/ProductTable.jsx @@ -41,8 +41,9 @@ export default function ProductTable({ cart, updateCart }) { setProducts(body); }; fetchProducts(); - }); + }, []); + return (