Download Amazon-Clone-PERN-stack/src/components/Card.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/src/components/Card.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/src/components/Card.js
-
curl -L -o Card.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/Amazon-Clone-PERN-stack/src/components/Card.js
796 Bytes
| 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; | |