Socket
Socket
Sign inDemoInstall

interval-hooks

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    interval-hooks

This package provides React hooks for running code at intervals.


Version published
Weekly downloads
938
decreased by-8.04%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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.

FAQs

Last updated on 22 Oct 2021

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc