-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathHome.jsx
More file actions
31 lines (26 loc) · 790 Bytes
/
Home.jsx
File metadata and controls
31 lines (26 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import React, { useEffect, useState } from "react";
import Cart from "../Components/Cart";
import NavBar from "../Components/NavBar";
import ProductTable from "../Components/ProductTable";
function Home() {
const [open, setOpen] = useState(false);
const [cart, updateCart] = useState(JSON.parse(localStorage.getItem('cart') || '[]'));
useEffect(() => {
localStorage.setItem('cart',JSON.stringify(cart));
}, [cart])
const cartSize = () => {
let size = 0;
for(let cartItem of cart){
size += cartItem.quantity
}
return size;
}
return (
<main>
<NavBar cartSize={cartSize()} {...{ setOpen }} />
<Cart {...{ open, setOpen, cart, updateCart }} />
<ProductTable {...{ cart, updateCart }} />
</main>
);
}
export default Home;