React timer hook is a custom react hook built to handle timers(countdown), stopwatch and time logic/state in your react component.
Package Exports
react-timer-hook
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-timer-hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
react-timer-hook
React timer hook is a custom react hook, built to handle timer, stopwatch, and time logic/state in your react component.
useTimer: Timers (countdown timer)
useStopwatch: Stopwatch (count up timer)
useTime: Time (return current time)
Setup
yarn add react-timer-hook OR npm install --save react-timer-hook
this will define the initial stopwatch offset example: const stopwatchOffset = new Date(); stopwatchOffset.setSeconds(stopwatchOffset.getSeconds() + 300); this will result in a 5 minutes offset and stopwatch will start from 0:0:5:0 instead of 0:0:0:0
Values
key
Type
Description
seconds
number
seconds value
minutes
number
minutes value
hours
number
hours value
days
number
days value
isRunning
boolean
flag to indicate if stopwatch is running or not
start
function
function to be called to start/resume stopwatch
pause
function
function to be called to pause stopwatch
reset
function
function to be called to reset stopwatch to 0:0:0:0, you can also pass offset parameter to this function to reset stopwatch with offset, similar to how offsetTimestamp will offset the initial stopwatch time
if set to 12-hour time will be formatted with am/pm
Values
key
Type
Description
seconds
number
seconds value
minutes
number
minutes value
hours
number
hours value
ampm
string
am/pm value if 12-hour format is used
Deprecation Warning:
Starting from v1.1.0 and above default export useTimer is deprecated, your old code will still work but it is better to start using named exports { useTimer, useStopwatch, useTime }