Skip to content

Instantly share code, notes, and snippets.

@ogun
Created February 3, 2023 10:56
Show Gist options
  • Save ogun/8391794a1d69651046d17416178a5ea2 to your computer and use it in GitHub Desktop.
Save ogun/8391794a1d69651046d17416178a5ea2 to your computer and use it in GitHub Desktop.
React Sorusu
const calculateETA = (time: string) => Math.ceil(moment.duration(moment(time).diff(moment())).asMinutes());
React.useEffect(() => {
if (eta) {
setState(calculateETA(eta));
const intervalId = setInterval(() => {
setState(calculateETA(eta));
}, 60000);
return () => clearInterval(intervalId);
}
}, [eta]);
return state && state > 0 ? ( ... )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment