
Research
PyPI Package Disguised as Instagram Growth Tool Harvests User Credentials
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
react-use-precision-timer
Advanced tools
A versatile precision timer hook for React. Doubles as a stopwatch.
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
import { useTimer } from "react-use-precision-timer";
In your function component:
const callback = React.useCallback(() => console.log('Boom'), []);
// The callback will be called every 1000 milliseconds.
const timer = useTimer({ delay: 1000 }, callback);
In a handler or effect:
timer.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:
import { useDelay } from 'react-use-precision-timer';
In your function component:
const callback = React.useCallback(() => console.log('Boom'), []);
// Will call once after 1000ms.
const onceTimer = useDelay(1000, callback);
In a handler or effect:
onceTimer.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:
import { useStopwatch } from "react-use-precision-timer";
const 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.
import { useMomentaryBool } from 'react-use-precision-timer';
In your function component:
// Toggle to true, then back to false after 1000ms.
const [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.
FAQs
A versatile precision timer hook for React. Doubles as a stopwatch.
The npm package react-use-precision-timer receives a total of 6,807 weekly downloads. As such, react-use-precision-timer popularity was classified as popular.
We found that react-use-precision-timer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Ā It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.