I'm currently working on fetching data from an API using SWR and dynamically setting the currency based on user preferences through context API. However, I'm facing issues as I am unable to view any data. Can someone please provide assistance or insights into where I might be going wrong?
Below is the code snippet:
import React from 'react'
import useSWR from "swr";
import {CryptoState} from "../context/cryptoContext"
import {useContext} from "react";
function Trending() {
const {currency } = useContext(CryptoState)
const address = `https://api.coingecko.com/api/v3/coins/markets?vs_currency=${currency}&order=gecko_desc&per_page=10&page=1&sparkline=false&price_change_percentage=24h`;
const fetcher = async (url) => await axios.get(url).then((res) => res.data);
const { data, error } = useSWR(address, fetcher);
if (error) <p>Loading failed...</p>;
if (!data) <h1>Loading...</h1>;
return (
<div>
{data && console.log(data)}
</div>
)
}
export default Trending;