⏱️ use-timer
Simple timer turned into React Hooks. Read about Hooks feature.
Installation
npm i use-timer
With Yarn:
yarn add use-timer
Demo
🚀 Try last production version on Netlify!
https://use-timer.netlify.app/
Usage
Basic timer
;; ;
Decremental timer
;
Timer with end time
;
Advance time
This works for all types of timer (incremental and decremental).
; start;advanceTime10; console.logtime; // 30
Callbacks
Some callback functions can be provided.
When time is over
;
When time is updated
;
Configuration
The configuration and all its parameters are optional.
Property | Type | Default value | Description |
---|---|---|---|
autostart | boolean | false | Pass true to start timer automatically |
endTime | number | null | The value for which timer stops |
initialTime | number | 0 | The starting value for the timer |
interval | number | 1000 | The interval in milliseconds |
onTimeOver | function | Callback function that is called when time is over | |
onTimeUpdate | function | Callback function that is called when time is updated | |
step | number | 1 | The value to add to each increment / decrement |
timerType | string | "INCREMENTAL" | The choice between a value that increases ("INCREMENTAL") or decreases ("DECREMENTAL") |