-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckoutProduct.js
38 lines (34 loc) · 1.06 KB
/
CheckoutProduct.js
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
32
33
34
35
36
37
38
import React from "react";
import "./CheckoutProduct.css";
import { useStateValue } from "./StateProvider";
const CheckoutProduct = ({ id, image, title, price, rating }) => {
const [{ basket }, dispatch] = useStateValue();
const removeFromBasket = () => {
// remove the item from the basket
dispatch({
type: "REMOVE_FROM_BASKET",
id:id,
});
};
return (
<div className="checkoutProduct">
<img className="checkoutProduct__image" src={image} alt="Product" />
<div className="checkoutProduct__info">
<p className="checkoutProduct__title">{title}</p>
<p className="checkoutProduct__price">
<small>$</small>
<strong>{price}</strong>
</p>
<div className="checkoutProduct__rating">
{Array(rating)
.fill()
.map((_, i) => (
<p>🌟</p>
))}
</div>
<button onClick={removeFromBasket}>Remove from Basket</button>
</div>
</div>
);
};
export default CheckoutProduct;