Skip to content

Instantly share code, notes, and snippets.

@infantiablue
Last active April 28, 2021 13:23
Show Gist options
  • Save infantiablue/957243733a64cf3c1935afb0f7cd66f0 to your computer and use it in GitHub Desktop.
Save infantiablue/957243733a64cf3c1935afb0f7cd66f0 to your computer and use it in GitHub Desktop.
useEffect(() => {
fetchData().then((chartData) => {
initChart(chartData);
setLatestPrice(parseFloat(chartData.price[chartData.price.length - 1]).toFixed(2));
});
const timerID = setInterval(() => {
fetchData().then((chartData) => {
updateChart(chartData);
setLatestPrice(parseFloat(chartData.price[chartData.price.length - 1]).toFixed(2));
});
}, 1000 * 60);
return () => {
clearInterval(timerID);
};
}, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment