This package provides React hooks for running code at intervals.
npm install interval-hooksThis package provides React hooks for running code at intervals.
``bash
npm install interval-hooks
yarn add interval-hooks
`
The useInterval hook will run a function at a specific interval.
`js`
useInterval(() => {
console.log('This runs every 5 seconds.');
}, 5000);
You can set the delay to null to stop the interval from running.
`jsdelay
useInterval(() => {
console.log("This won't run because the is null.");`
}, null);
The useSynchronizedInterval hook is just like useInterval, however it will run all functions with the same delay at the same time.
`js
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.