Skip to content

useTimer ​

Category
Time

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

NameTypeDefaultNote
timestampnumber-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.autostartboolean-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

Contributors ​

Source • Demo