useCountdown
A hook to manage countdown timers.
Overview
useCountdown manages a numeric countdown. It provides start, stop, and reset controls, and can be configured to count down or up.
Demo
API Reference
function useCountdown(options: CountdownOptions): [number, CountdownControllers]Options
| Name | Type | Description |
|---|---|---|
countStart | number | Starting value. |
intervalMs | number | Interval speed in ms (default: 1000). |
countStop | number | Value to stop at (default: 0). |
isIncrement | boolean | If true, counts up instead of down. |
Usage Example
import { useCountdown } from 'react-hooks-ts'
function Timer() {
const [count, { startCountdown, stopCountdown, resetCountdown }] = useCountdown({
countStart: 60,
intervalMs: 1000
})
return (
<div>
<p>{count}</p>
<button onClick={startCountdown}>Start</button>
<button onClick={stopCountdown}>Stop</button>
<button onClick={resetCountdown}>Reset</button>
</div>
)
}