interval-hooks
Advanced tools
This package provides React hooks for running code at intervals.
Weekly downloads
Readme
This package provides React hooks for running code at intervals.
npm install interval-hooks
# or
yarn add interval-hooks
useInterval
The useInterval
hook will run a function at a specific interval.
useInterval(() => {
console.log('This runs every 5 seconds.');
}, 5000);
You can set the delay to null
to stop the interval from running.
useInterval(() => {
console.log("This won't run because the `delay` is null.");
}, null);
useSynchronizedInterval
The useSynchronizedInterval
hook is just like useInterval
, however it will run all functions with the same delay at the same time.
useSynchronizedInterval(() => {
console.log('These console logs will happen at the same time.');
}, 5000);
// wait 3 seconds...
useSynchronizedInterval(() => {
console.log('These console logs will happen at the same time.');
}, 5000);
Synchronized intervals are useful for calling functions that need to happen at the same time, like ticking clocks.
FAQs
This package provides React hooks for running code at intervals.
The npm package interval-hooks receives a total of 423 weekly downloads. As such, interval-hooks popularity was classified as not popular.
We found that interval-hooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.