-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathCoinGeckoDataDisplay.tsx
More file actions
50 lines (44 loc) · 1.69 KB
/
Copy pathCoinGeckoDataDisplay.tsx
File metadata and controls
50 lines (44 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { useEffect, useState } from 'react';
import fetchCoinGeckoDataDisplay from '../api/coinGeckoApi.tsx';
import CoinGeckoChart from '../components/CoinGeckoChart.tsx';
import CoinGeckoTable from '../components/CoinGeckoTable.tsx';
import CoinGeckoHeader from '../components/CoinGeckoHeader.tsx';
import './CoinGeckoDataDisplay.css'; // We'll create this file for styling
// Define a type for the CoinGecko data
interface CoinGeckoData {
prices: number[][]; // Adjust this type based on the actual structure of the data
}
const CoinGeckoDataDisplay: React.FC = () => {
const [data, setData] = useState<CoinGeckoData | null>(null); // Use the defined type
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const loadData = async () => {
try {
setLoading(true);
const CoinGeckoDataDisplay = await fetchCoinGeckoDataDisplay();
console.log("Fetched CoinGecko Data:", CoinGeckoDataDisplay); // Log the fetched data
setData(CoinGeckoDataDisplay);
setError(null);
} catch (err) {
setError('Failed to load data');
console.error(err);
} finally {
setLoading(false);
}
};
loadData();
}, []);
return (
<div>
<h1>CoinGecko Data Display</h1>
{loading && <p>Loading data...</p>}
{error && <p>Error: {error}</p>}
{!loading && !error && data && data.prices.length > 0 && (
<CoinGeckoChart data={data} /> // Render the CoinGeckoChart component
)}
{!loading && !error && data && data.prices.length === 0 && <p>No data available</p>}
</div>
);
};
export default CoinGeckoDataDisplay;