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