project_cryptoverse icon indicating copy to clipboard operation
project_cryptoverse copied to clipboard

TypeError: Cannot read properties of undefined (reading 'total')

Open ishitamittal1210 opened this issue 3 years ago • 8 comments

_Line 3:10: 'Button' is defined but never used no-unused-vars Line 6:74: 'MenuOutlined' is defined but never used no-unused-vars_

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

ishitamittal1210 avatar Dec 15 '21 08:12 ishitamittal1210

Screenshot (309)

ishitamittal1210 avatar Dec 15 '21 08:12 ishitamittal1210

Screenshot (312)

ishitamittal1210 avatar Dec 15 '21 08:12 ishitamittal1210

use globalStats?.total this worked for me!

Arif-arsh avatar Dec 17 '21 12:12 Arif-arsh

Also I am working on this project

Arif-arsh avatar Dec 17 '21 12:12 Arif-arsh

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

ishitamittal1210 avatar Dec 18 '21 14:12 ishitamittal1210

check the endpoints

Arif-arsh avatar Dec 19 '21 10:12 Arif-arsh

Look into your API routes , also try console logging globalStats.

StrikerCode08 avatar Dec 24 '21 14:12 StrikerCode08

Try including: if(isFetching) return 'Loading...'; underneath const cryptoDetails = data?.data?.coin; See if this works. It worked for me.

vvronskyFX avatar Dec 28 '21 04:12 vvronskyFX