[英]TypeError: Cannot read properties of undefined (reading 'map'). Error being thrown when I am trying to map over an array of cryptocurrencies
I am making a page which displays all the cryptocurrencies in the format of a card but I am getting an error.我正在制作一个以卡片格式显示所有加密货币的页面,但出现错误。
import { Card, Row, Col, Input } from 'antd'
import React from 'react'
import { Link } from 'react-router-dom'
import { useGetCryptosQuery } from '../services/CryptoApi'
import { useState } from 'react'
import millify from 'millify'
const Cryptocurrencies = () => {
const {data : cryptoList, isFetching } = useGetCryptosQuery()
const [cryptos,setCryptos] = useState(cryptoList?.data?.coins)
console.log(cryptos)
return (
<div>
<Row gutter = {[32,32]} className = "crypto-card-container">
{cryptos.map((currency) => (
<Col xs = {24} sm = {12} lg = {6} className = "crypto-card" key = {currency.id}>
<Link to = {'/crypto/${currency.id}'}>
<Card
title = {'${currency.rank}. ${currency.name}'}
extra = {<img className = "crypto-img" src = {currency.iconUrl}/>}
hoverable
>
<p>Price : {millify(currency.price)}</p>
<p>Market Cap : {millify(currency.marketCap)}</p>
<p>Daily Change : {millify(currency.change)}</p>
</Card>
</Link>
</Col>
))}
</Row>
</div>
)
}
export default Cryptocurrencies
what is the error in my map function and the callback I have used?我的 map function 和我使用的回调中的错误是什么?
You could use你可以使用
{.isFetching && cryptos.map((currency) => (... ))}
or或者
{?isFetching: <LoadingOrPlaceHolder>. cryptos.map((currency) => (... ))}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.