Gathering detailed insights and metrics for react-use-precision-timer
Gathering detailed insights and metrics for react-use-precision-timer
Gathering detailed insights and metrics for react-use-precision-timer
Gathering detailed insights and metrics for react-use-precision-timer
⏱️ A versatile precision timer hook for React. Doubles as a stopwatch.
npm install react-use-precision-timer
Typescript
Module System
Node Version
NPM Version
TypeScript (65.44%)
MDX (34.22%)
HTML (0.34%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
68 Stars
170 Commits
7 Forks
1 Watchers
3 Branches
1 Contributors
Updated on Jun 09, 2025
Latest Version
3.5.6
Package Id
react-use-precision-timer@3.5.6
Unpacked Size
68.27 kB
Size
13.75 kB
File Count
29
NPM Version
10.8.2
Node Version
20.18.0
Published on
Feb 18, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
28
Read the official documentation.
👁️ Live Demo
A React timer hook that calls the provided callback at regular intervals. Can be used as a stopwatch, too.
It's accurate, precise, and includes a rich set of options, functionality, and accessors.
setTimeout()
and Unix times, not ticks.Version 3 of this package features a complete redesign to reduce unnecessary renders, plus the addition of a new convenience hook.
React.useCallback()
to optimize render performance. Refer to the Quick Start section below.If this project helped save you time, please consider buying me a coffee, which powers my development (and life). Your support is much appreciated!
npm i react-use-precision-timer
1import { useTimer } from "react-use-precision-timer";
In your function component:
1const callback = React.useCallback(() => console.log('Boom'), []);
2// The callback will be called every 1000 milliseconds.
3const timer = useTimer({ delay: 1000 }, callback);
In a handler or effect:
1timer.start();
The following functions can be used to control the Timer:
timer.start()
- Start the timer. If already started, will restart the timer. You can optionally pass a start time in Unix epoch milliseconds.timer.stop()
- Stop the timer.timer.pause()
- Pause the timer.timer.resume()
- Resume the timer.Refer to Timer for all available functions, including getters for elapsed times.
If you'd like to run a callback after a one-time delay, use the helper hook useDelay:
1import { useDelay } from 'react-use-precision-timer';
In your function component:
1const callback = React.useCallback(() => console.log('Boom'), []); 2// Will call once after 1000ms. 3const onceTimer = useDelay(1000, callback);
In a handler or effect:
1onceTimer.start();
This will call the callback after the provided 1000 millisecond delay only once.
The timer also functions as a stopwatch when no delay is provided. You can use the helper hook useStopwatch:
1import { useStopwatch } from "react-use-precision-timer";
1const stopwatch = useStopwatch();
Use start()
, stop()
, pause()
, and resume()
to control the stopwatch.
Stopwatch is a Timer object. Refer to Timer's getters to retrieve elapsed running time, paused time, and so forth.
Calling start while a stopwatch is already running will restart it.
For convenience, the useMomentaryBool hook has been included to momentarily toggle a boolean. This wraps the useDelay hook.
This is very useful for momentary notifications, such as a copy button that shows a momentary checkmark to indicate the operation succeeded.
1import { useMomentaryBool } from 'react-use-precision-timer';
In your function component:
1// Toggle to true, then back to false after 1000ms. 2const [value, toggle] = useMomentaryBool(false, 1000);
Calling toggle()
will set the boolean to true
, then back to false
after a 1000 millisecond delay.
See useTimer for all other hook options and timer functions.
Type definitions have been included for TypeScript support.
Favicon by Twemoji.
Open source software is awesome and so are you. 😎
Feel free to submit a pull request for bugs or additions, and make sure to update tests as appropriate. If you find a mistake in the docs, send a PR! Even the smallest changes help.
For major changes, open an issue first to discuss what you'd like to change.
If you found this project helpful, let the community know by giving it a star: 👉⭐
Want to support the project? Feel free to grab me a coffee, which is my main source of fuel for development:
See LICENSE.md.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More