feat: add shopping cart

This commit is contained in:
mike 2024-10-12 13:59:08 -04:00
parent aa7d7e8656
commit 556a7f8fe2

View file

@ -0,0 +1,30 @@
const Cart = (props) => {
return (
<section>
{props.cart ? (
<div>
<h2>Cart</h2>
{props.cart.map((item) =>
<CartItem item={item} qty={item.qty} />
)}
</div>
) : (<h2>Your cart is empty</h2>)}
</section>
)
}
function CartItem({item, qty}) {
const {name, price, img} = item;
return (
<div>
<img src={img} alt={name} />
<h3>{name}</h3>
<p>Qty: {qty}</p>
<p>{price}</p>
<p>{price * qty}</p>
</div>
)
}