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 ( {coin.name} {coin?.symbol}   0 ? "rgb(14, 203, 129)" : "red", fontWeight: 500, }} > {profit && "+"} {coin?.price_change_percentage_24h?.toFixed(2)}% {symbol} {numberWithCommas(coin?.current_price.toFixed(2))} ); }); const responsive = { 0: { items: 2, }, 512: { items: 4, }, }; return (
); }; export default Carousel;