-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCurrency.js
47 lines (40 loc) · 1.28 KB
/
Currency.js
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
import React, { useEffect, useState } from "react";
const Currency = () => {
const [currencyData, setCurrencyData] = useState({});
const updateCurrencyContainer = async () => {
try {
const response = await fetch("/api/currency");
const data = await response.json();
setCurrencyData(data.rates || {});
} catch (error) {
console.error("Error fetching currency data:", error);
}
};
useEffect(() => {
updateCurrencyContainer();
const intervalId = setInterval(updateCurrencyContainer, 10000);
return () => clearInterval(intervalId);
}, []);
return (
<div id="currencyContainer">
{Object.entries(currencyData).length > 0 ? (
Object.entries(currencyData).map(([currency, rate], index) => (
<div
key={index}
className="flex justify-between items-center border-b border-gray-300 py-2 currency-row"
>
<div className="bg-bg-cur-symb-grey font-bold text-white rounded p-2 m-4 ml-4">
{currency}
</div>
<div className="text-5xl text-cur-text-tan mr-4 max-sm:text-4xl">
{rate}
</div>
</div>
))
) : (
<p>Loading currency data...</p>
)}
</div>
);
};
export default Currency;