Created
October 24, 2023 19:41
-
-
Save Alzemiro/33e01efd0ab1cd40115c0f1f4b8af18f to your computer and use it in GitHub Desktop.
To Sther
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
export function App(props) { | |
const [time, setTime] = useState(25000); | |
const [start, setStart] = useState(false); | |
useEffect(() => { | |
const timer = setInterval(() => { | |
if (start && time > 0) { | |
setTime(time - 1); | |
} | |
}, 1000); | |
return () => clearInterval(timer); | |
}, [start, time]); | |
function startStopClock() { | |
setStart(!start); | |
} | |
return ( | |
<div className='App'> | |
<h1>{time.toString()}</h1> | |
<button onClick={startStopClock}>{`${!start ? 'Start' : 'Stop'}`}</button> | |
</div> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment