Created
December 14, 2024 21:38
-
-
Save CodingAbdullah/4db82a40a50a592285a5ac2a4e79c195 to your computer and use it in GitHub Desktop.
Historic data related to Bitcoin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { FC } from 'react'; | |
| import { useQuery } from '@tanstack/react-query'; | |
| import { BitcoinHistoricPriceAction } from '../utilFunctions/bitcoinPrice.ts'; | |
| const BitcoinPriceTable: FC = () => { | |
| const bitcoinPriceQuery = useQuery({ | |
| queryKey: ['Bitcoin Price'], | |
| queryFn: BitcoinHistoricPriceAction | |
| }); | |
| // Conditionally render price table | |
| if (bitcoinPriceQuery.isLoading || bitcoinPriceQuery.isPending) { | |
| return <div>Loading...</div> | |
| } | |
| else if (bitcoinPriceQuery.error || bitcoinPriceQuery.isError){ | |
| return <div>Error loading price data</div> | |
| } | |
| else { | |
| return ( | |
| <table style={{ width: '50%', marginLeft: 'auto', marginRight: 'auto' }}> | |
| <thead> | |
| <tr> | |
| <th>Day</th> | |
| <th>Price</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| { | |
| bitcoinPriceQuery.data.coinPrices.map(dayPrice => { | |
| return ( | |
| <> | |
| <tr> | |
| <td>{dayPrice.time}</td> | |
| <td>{dayPrice.price}</td> | |
| </tr> | |
| </> | |
| ) | |
| }) | |
| } | |
| </tbody> | |
| </table> | |
| ) | |
| } | |
| } | |
| export default BitcoinPriceTable; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment