project_cryptoverse
project_cryptoverse copied to clipboard
TypeError: Cannot read properties of undefined (reading 'total')
import React from 'react'; // eslint-disable-next-line import millify from 'millify'; import { Typography, Row, Col, Statistic } from 'antd'; // eslint-disable-next-line import { Link } from 'react-router-dom';
import { useGetCryptosQuery } from '../services/cryptoApi';
const { Title } = Typography;
const Homepage = () => { const { data, isFetching } = useGetCryptosQuery(10); const globalStats = data?.data?.stats; if(isFetching) return 'Loading...'; return ( <> <Title level={2} className="heading">Global Crypto Stats</Title> <Row> <Col span={12}><Statistic title="Total Cryptocurrencies" value={globalStats.total} /></Col> <Col span={12}><Statistic title="Total Exchanges" value="5" /></Col> <Col span={12}><Statistic title="Total Market Cap" value="5" /></Col> <Col span={12}><Statistic title="Total 24h Volume" value="5" /></Col> <Col span={12}><Statistic title="Total Markets" value="5" /></Col> </Row> </> ) }
export default Homepage
use globalStats?.total this worked for me!
Also I am working on this project
use globalStats?.total this worked for me!
It didn't worked for me by doing this the value in front of total cryptocurrencies is displayed as 0 instead of fetching the real data
check the endpoints
Look into your API routes , also try console logging globalStats.
Try including: if(isFetching) return 'Loading...';
underneath const cryptoDetails = data?.data?.coin;
See if this works. It worked for me.