mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2024-12-26 14:20:43 -05:00
feat: add shopping cart
This commit is contained in:
parent
aa7d7e8656
commit
556a7f8fe2
1 changed files with 30 additions and 0 deletions
|
@ -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>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue