Skip to content

Instantly share code, notes, and snippets.

@anthowave
Created November 3, 2020 22:24
Show Gist options
  • Save anthowave/600c754024d3dfde97af97540c68f077 to your computer and use it in GitHub Desktop.
Save anthowave/600c754024d3dfde97af97540c68f077 to your computer and use it in GitHub Desktop.
CountdownTimer react component
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