Skip to Content
ohooks

useCountdown

Manages a configurable countdown (or count-up) timer with start, pause, and reset controls.

Loading preview...

The useCountdown hook steps a numeric counter toward a target value on a fixed interval and provides start, pause, and reset controls along with a completion callback.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useCountdown.json

Usage

Examples

Resend Verification Code Timer

Use onComplete to unlock an action when the countdown reaches countStop, and call reset followed by start to restart the timer.

Count-Up Timer

Set isIncrement: true and a higher countStop to count upward instead of downward.

API Reference

UseCountdownOptions

Configuration options for the countdown timer.

Property
Specification
countStartrequired
number
Starting count value
countStop?
numberdefault:0
Target count value where the timer stops
intervalMs?
numberdefault:1000
Tick interval in milliseconds
isIncrement?
uniondefault:false
Count up instead of down
autoStart?
uniondefault:false
Start the countdown automatically on mount
onTick?
function
Callback fired on every tick with the updated count
onComplete?
function
Callback fired when the countdown reaches countStop

UseCountdownReturn

Timer state and control methods returned by the hook.

Property
Specification
count
number
Current count value
isRunning
union
Whether the countdown timer is currently active
start
function
Starts or resumes the countdown
pause
function
Pauses the countdown
reset
function
Stops the countdown and resets count back to countStart