@scaleway/use-countdown
v1.0.2
Published
Tiny react hook for a countdown
Maintainers
Keywords
Readme
@scaleway/use-countdown
A react hook acting as a countdown timer
Install
pnpm add @scaleway/use-countdownUsage
As a React hook
import { useCountdown } from '@scaleway/use-countdown'
const Component = () => {
const { timeLeft, startCountdown } = useCountdown(10)
return (
<div>
<p>Time left: {timeLeft} seconds</p>
<button onClick={startCountdown}>Start Countdown</button>
</div>
)
}You can also trigger the countdown at the hook instanciation
import { useCountdown } from '@scaleway/use-countdown'
const Component = () => {
const { timeLeft } = useCountdown(10, true)
return (
<div>
<p>Time left: {timeLeft} seconds</p>
</div>
)
}