繁体   English   中英

类型错误:无法读取未定义的属性(读取“地图”)。 当我尝试通过一系列加密货币 map 时抛出错误

[英]TypeError: Cannot read properties of undefined (reading 'map'). Error being thrown when I am trying to map over an array of cryptocurrencies

我正在制作一个以卡片格式显示所有加密货币的页面,但出现错误。

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
 

我的 map function 和我使用的回调中的错误是什么?

你可以使用

 {.isFetching && cryptos.map((currency) => (... ))}

或者

 {?isFetching: <LoadingOrPlaceHolder>. cryptos.map((currency) => (... ))}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM