简体   繁体   English

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

[英]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.

相关问题 TypeError:无法读取未定义的属性(正在读取“映射”)(JavaScript 数组映射) - TypeError: Cannot read properties of undefined (reading 'map') (JavaScript array map) 错误:未捕获的类型错误:无法读取未定义的属性(读取“地图”) - Error: Uncaught TypeError: Cannot read properties of undefined (reading 'map') 当我在我的 React 应用程序中使用 map 方法时,出现此错误“无法读取未定义的属性(读取‘地图’)” - I am getting this error "Cannot read properties of undefined (reading 'map')" when i use map method in my react app 尝试映射数组时出现错误。 TypeError:无法读取未定义的属性“ map” - Getting error while trying to map over array. TypeError: Cannot read property 'map' of undefined 尝试从 firebase 集合中提取数据时出错 REACT:类型错误:无法读取未定义的属性(读取“地图”) - Getting error when trying to pull data from firebase collection REACT: TypeError: Cannot read properties of undefined (reading 'map') 无法显示数组项和标志错误:未捕获的类型错误:无法读取未定义的属性(读取“地图”) - failed to display array items and flags error: Uncaught TypeError: Cannot read properties of undefined (reading 'map') 我正在尝试从数据库中获取 map mydata 但我收到此错误。 TypeError:无法读取未定义的属性“地图” - I am trying to map mydata from the database but i am getting this error. TypeError: Cannot read property 'map' of undefined 类型错误:当我尝试访问 API 调用数据时,无法读取未定义的属性“映射” - TypeError: Cannot read property 'map' of undefined when I am trying to access API call data 使用 ipcRenderer 时出现错误(类型错误无法读取未定义的属性(读取“发送”)) - I am getting an error when using ipcRenderer (typeerror cannot read properties of undefined (reading 'send')) TypeError:无法读取未定义的属性(读取“地图”) - State 返回未定义 - TypeError: Cannot read properties of undefined (reading 'map') - State returns undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM