useTimer ​
Hook that creates a timer functionality
typescript
import { useTimer } from '@siberiacancode/reactuse';
Usage ​
typescript
const { days, hours, minutes, seconds, toggle, pause, start, restart, running } = useTimer(1000, () => console.log('ready'));
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
timestamp | number | - | The timestamp value that define for how long the timer will be running |
callback | () => void | - | The function to be executed once countdown timer is expired |
options.autostart | boolean | - | The flag to decide if timer should start automatically |
options.onTick | (timestamp: number) => void | - | The function to be executed on each tick of the timer |