import React, { useState, useEffect } from 'react';
const Countdown = (props: { ms: number; delta?: number }) => {
const [time, setTime] = useState(props.ms);
useEffect(() => {
const interval = setInterval(() => {
setTime(prevTime => {
if (prevTime <= 0) {
clearInterval(interval);
return 0;
}
return prevTime - (props.delta || 1000);
});
}, 1000);
return () => clearInterval(interval);
}, [props.delta]);
return <div>{time / 1000}s</div>;
};