const { data, isFetching } = useGetCryptoDetailsQuery(coinId)
console.log(data)
console.log(data?.data?.coin.name)
const cryptoDetails = data?.data?.coin
console.log(cryptoDetails.name)
console.log(cryptoDetails.name)
const cryptoDetails = data?.data?.coin
console.log(data?.data?.coin.name)
reload the browser, than I got the result as I say before.
But in case if I do uncomment the console.log(cryptoDetails.name)
& without any reload, It show the data. But then when I reload the browser, It show me the error.
import React, { useState } from 'react'
import millify from 'millify'
import HTMLReactParser from 'html-react-parser'
import { useParams } from 'react-router-dom'
import { Row, Col, Typography, Select } from 'antd'
import { MoneyCollectOutlined, DollarCircleOutlined, FundOutlined, ExclamationCircleOutlined, StopOutlined, TrophyOutlined, CheckOutlined, NumberOutlined, ThunderboltOutlined } from '@ant-design/icons';
import { useGetCryptoDetailsQuery } from '../services/cryptoApi'
const { Title, Text } = Typography
const { Option } = Select
const CryptoDetails = () => {
const { coinId } = useParams()
const [timeperiod, setTimeperiod] = useState('7d')
const { data, isFetching } = useGetCryptoDetailsQuery(coinId)
console.log(data)
const cryptoDetails = data?.data?.coin
console.log(data?.data?.coin)
console.log(cryptoDetails.name)
console.log(data?.data?.coin.name)
// const stats = [
// { title: 'Price to USD', value: `$ ${cryptoDetails.price && millify(cryptoDetails.price)}`, icon: <DollarCircleOutlined /> },
// { title: 'Rank', value: cryptoDetails.rank, icon: <NumberOutlined /> },
// { title: '24h Volume', value: `$ ${cryptoDetails.volume && millify(cryptoDetails.volume)}`, icon: <ThunderboltOutlined /> },
// { title: 'Market Cap', value: `$ ${cryptoDetails.marketCap && millify(cryptoDetails.marketCap)}`, icon: <DollarCircleOutlined /> },
// { title: 'All-time-high(daily avg.)', value: `$ ${millify(cryptoDetails.allTimeHigh.price)}`, icon: <TrophyOutlined /> },
// ];
return (
<Col className='coin-detail-container'>
<Col className='coin-heading-container'>
<Title level={2} className='coin-name'>
{/* {cryptoDetails.name}({cryptoDetails.slug}) Price */}
</Title>
<p>
{/* {cryptoDetails.name} live price in US dollars. */}
View value statistics,market cap & supply
</p>
</Col>
<Select
defaultValue='7d'
className='select-timeperiod'
placeholder='Select Time Period'
onChange={value => setTimeperiod(value)}
>
{time.map(date =>
<Option key={date}>{date}</Option>
)}
</Select>
</Col>
)
}
export default CryptoDetails
import {
createApi,
fetchBaseQuery
} from '@reduxjs/toolkit/query/react'
const baseUrl = 'https://coinranking1.p.rapidapi.com'
const createRequest = url => ({
url,
headers: cryptoApiHeaders
})
export const cryptoApi = createApi({
reducerPath: 'cryptoApi',
baseQuery: fetchBaseQuery({
baseUrl
}),
endpoints: builder => ({
getCryptos: builder.query({
query: count => createRequest(`/coins?limit=${count}`)
}),
getCryptoDetails: builder.query({
query: coinId => createRequest(`/coin/${coinId}`)
})
})
})
export const {
useGetCryptosQuery,
useGetCryptoDetailsQuery
} = cryptoApi