Created
November 3, 2020 22:24
-
-
Save anthowave/600c754024d3dfde97af97540c68f077 to your computer and use it in GitHub Desktop.
CountdownTimer react component
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 from 'react' | |
export default function CountdownTimer({ startSeconds }) { | |
const [seconds, setSeconds] = React.useState(startSeconds); | |
const timeoutCallback = React.useCallback(() => { | |
if(seconds >= 1) | |
setSeconds(seconds - 1); | |
}, [seconds]); | |
React.useEffect(() => { | |
setTimeout(() => { | |
timeoutCallback(); | |
}, 1000); | |
}, [timeoutCallback]); | |
return ( | |
<p className="seconds" > | |
{ seconds } | |
</p> | |
) | |
} | |
// <CountdownTimer startSeconds={3} /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment