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
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
countStartrequirednumber
Starting count value
countStop?numberdefault:0
Target count value where the timer stops
Full Signature
intervalMs?numberdefault:1000
Tick interval in milliseconds
Full Signature
isIncrement?uniondefault:false
Count up instead of down
Full Signature
autoStart?uniondefault:false
Start the countdown automatically on mount
Full Signature
onTick?function
Callback fired on every tick with the updated count
Full Signature
Parameters
(countnumberonComplete?function
Callback fired when the countdown reaches
countStopFull Signature
Parameters
(UseCountdownReturn
Timer state and control methods returned by the hook.
Property
Specification
countnumber
Current count value
isRunningunion
Whether the countdown timer is currently active
Full Signature
startfunction
Starts or resumes the countdown
Full Signature
pausefunction
Pauses the countdown
Full Signature
resetfunction
Stops the countdown and resets
count back to countStartFull Signature