I am having trouble iterating through this api and displaying the data. You can see the sample api in here https://api.coingecko.com/api/v3/search/trending. I would be really grateful if you help me
interface
export interface Item {
id: string;
name: string;
symbol: string;
market_cap_rank: number;
thumb: string;
large: string;
score: number;
}
export interface Coin {
item: Item;
}
export interface ResponseObject{
coins: Coin[];
}
React Code
const TRENDING = 'https://api.coingecko.com/api/v3/search/trending'
const Home = () => {
const [trending, setTrending] = useState<ResponseObject[]>([])
useEffect(() => {
axios.get<ResponseObject[]>(TRENDING).then((response) => {
setTrending(response.data)
console.log(response.data)
})
}, [])
return {response.coins?.map((p) => {
return <div>{p.item.name}
</div>;
}
export default Home
Sample Api
{
"coins":[
{
"item":{
"id":"superfarm",
"name":"SuperFarm",
"symbol":"SUPER",
"market_cap_rank":235,
"thumb":"https://assets.coingecko.com/coi1613975899",
"large":"https://assets.coingecko.com/coins
"score":0
}
}
],
}