Data is not updated until you refresh the page
Closed this issue · 4 comments
Hello, what should I do to update the data every 5 seconds?
@Flyingfinger12 on this file: src/section/CurrencyData.js
you can do this:
useEffect(() => { setCoinData([]); const coin = async () => { const data = await getCoinData(currency); setCoinData(data); supplyPercent.current = Number(((data.market_data.total_supply / data.market_data.max_supply) * 100)).toFixed(0); marketCapToBTC.current = 0; volume24ToBtc.current = 0; data.tickers.forEach(item => { marketCapToBTC.current += item.converted_volume.btc volume24ToBtc.current += item.converted_last.btc }) } setInterval(() => { coin(); }, 5000) }, [currency]);
tell me if its worked
@Flyingfinger12 you can do this temporarily
useEffect(() => { setCoinData([]); const coin = async () => { let data; const coinData = await getCoinData(currency); setCoinData(coinData); setInterval(async () => { data = await getCoinData(currency); }, 5000); supplyPercent.current = Number( (data.market_data.total_supply / data.market_data.max_supply) * 100 ).toFixed(0); marketCapToBTC.current = 0; volume24ToBtc.current = 0; data.tickers.forEach((item) => { marketCapToBTC.current += item.converted_volume.btc; volume24ToBtc.current += item.converted_last.btc; }); }; coin(); }, [currency]);
Edit: The code is working, it updates a little late, but I think I can handle the rest, thank you very much.