Open Vitaminaq opened 2 years ago
import { useEffect, useState } from 'react'; let count = 60; function App() { const [countDown, setCountDown] = useState(count); useEffect(() => { const start = Date.now(); const timer = setInterval(() => { const t = Math.round((Date.now() - start)/1000); const c = count - t; c <=0 && clearInterval(timer); setCountDown(c > 0 ? c : 0); }, 1000); return () => { clearInterval(timer); } }, []); return ( <div className="App"> {countDown} </div> ); } export default App;