Download react-crypto-tracker/src/components/Banner/Carousel.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/components/Banner/Carousel.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/components/Banner/Carousel.js
-
curl -L -o Carousel.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-crypto-tracker/src/components/Banner/Carousel.js
2.42 kB
| import { makeStyles } from "@material-ui/core"; | |
| import axios from "axios"; | |
| import { useEffect, useState } from "react"; | |
| import AliceCarousel from "react-alice-carousel"; | |
| import { Link } from "react-router-dom"; | |
| import { TrendingCoins } from "../../config/api"; | |
| import { CryptoState } from "../../CryptoContext"; | |
| import { numberWithCommas } from "../CoinsTable"; | |
| const Carousel = () => { | |
| const [trending, setTrending] = useState([]); | |
| const { currency, symbol } = CryptoState(); | |
| const fetchTrendingCoins = async () => { | |
| const { data } = await axios.get(TrendingCoins(currency)); | |
| console.log(data); | |
| setTrending(data); | |
| }; | |
| useEffect(() => { | |
| fetchTrendingCoins(); | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, [currency]); | |
| const useStyles = makeStyles((theme) => ({ | |
| carousel: { | |
| height: "50%", | |
| display: "flex", | |
| alignItems: "center", | |
| }, | |
| carouselItem: { | |
| display: "flex", | |
| flexDirection: "column", | |
| alignItems: "center", | |
| cursor: "pointer", | |
| textTransform: "uppercase", | |
| color: "white", | |
| }, | |
| })); | |
| const classes = useStyles(); | |
| const items = trending.map((coin) => { | |
| let profit = coin?.price_change_percentage_24h >= 0; | |
| return ( | |
| <Link className={classes.carouselItem} to={`/coins/${coin.id}`}> | |
| <img | |
| src={coin?.image} | |
| alt={coin.name} | |
| height="80" | |
| style={{ marginBottom: 10 }} | |
| /> | |
| <span> | |
| {coin?.symbol} | |
| | |
| <span | |
| style={{ | |
| color: profit > 0 ? "rgb(14, 203, 129)" : "red", | |
| fontWeight: 500, | |
| }} | |
| > | |
| {profit && "+"} | |
| {coin?.price_change_percentage_24h?.toFixed(2)}% | |
| </span> | |
| </span> | |
| <span style={{ fontSize: 22, fontWeight: 500 }}> | |
| {symbol} {numberWithCommas(coin?.current_price.toFixed(2))} | |
| </span> | |
| </Link> | |
| ); | |
| }); | |
| const responsive = { | |
| 0: { | |
| items: 2, | |
| }, | |
| 512: { | |
| items: 4, | |
| }, | |
| }; | |
| return ( | |
| <div className={classes.carousel}> | |
| <AliceCarousel | |
| mouseTracking | |
| infinite | |
| autoPlayInterval={1000} | |
| animationDuration={1500} | |
| disableDotsControls | |
| disableButtonsControls | |
| responsive={responsive} | |
| items={items} | |
| autoPlay | |
| /> | |
| </div> | |
| ); | |
| }; | |
| export default Carousel; | |