interval-hooks
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Interval hooks

This package provides React hooks for running code at intervals.

Install

npm install interval-hooks

# or

yarn add interval-hooks

Usage

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.

Readme

Keywords

none

Package Sidebar

Install

npm i interval-hooks

Weekly Downloads

938

Version

0.2.0

License

MIT

Unpacked Size

24.1 kB

Total Files

16

Last publish

Collaborators

  • ryanto