adrianhajdin / project_cryptoverse

Cryptocurrency App powered by RapidAPI
https://jsmastery.pro
1.32k stars 401 forks source link

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

Open ishitamittal1210 opened 2 years ago

ishitamittal1210 commented 2 years ago

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 ( <>

Global Crypto Stats
    <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 commented 2 years ago

Screenshot (309)

ishitamittal1210 commented 2 years ago

Screenshot (312)

Arif-arsh commented 2 years ago

use globalStats?.total this worked for me!

Arif-arsh commented 2 years ago

Also I am working on this project

ishitamittal1210 commented 2 years ago

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

Arif-arsh commented 2 years ago

check the endpoints

StrikerCode08 commented 2 years ago

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

vvronskyFX commented 2 years ago

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