File size: 796 Bytes
f5071ca |
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 |
import React from "react";
import { useHistory } from "react-router-dom";
import "./../css/Card.css";
import "bootstrap/dist/css/bootstrap.css";
function Card({ name, img, price, rating, id }) {
const history = useHistory();
const handleClickForRedirect = () => {
history.push(`/${id}`);
};
const getrating = () => {
const flooredRating = Math.floor(rating);
const arr = [];
for (let i = 0; i < flooredRating; i++) {
arr.push("⭐");
}
return arr;
};
return (
<div className="product-card" onClick={handleClickForRedirect}>
<div className="d-flex flex-column p-3">
<p>{name}</p>
<strong>${price}</strong>
<span>{getrating()}</span>
</div>
<img src={img} style={{ padding: "10px", height: "90%" }} alt="img" />
</div>
);
}
export default Card;
|