Skip to content

Instantly share code, notes, and snippets.

@clonalejandro
Last active October 26, 2022 18:35
Show Gist options
  • Save clonalejandro/f77ede01e3422ec1ff673d893e1a270e to your computer and use it in GitHub Desktop.
Save clonalejandro/f77ede01e3422ec1ff673d893e1a270e to your computer and use it in GitHub Desktop.
import { useState, useEffect } from 'react'
export const useCountdown = (time: number) => {
const [count, setCount] = useState(time)
useEffect(() => {
setTimeout(() => {
if (count) {
setCount((prevCount: number) => prevCount - 1)
}
}, 1000)
}, [count])
return count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment