Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-interval

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-interval

React hook for setting an interval as posted on overreacted.io

  • 1.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37K
decreased by-4.01%
Maintainers
1
Weekly downloads
 
Created
Source

use-interval

React hook for setting an interval as posted on overreacted.io

NPM JavaScript Style Guide

Dan Abramov's blog post explaining why you cannot just use setInterval within useEffect.

Used by

Install

npm install --save use-interval

Usage

import * as React from 'react'

import useInterval from 'use-interval'

const Example = () => {
  let [count, setCount] = React.useState(0);

  useInterval(() => {
    // Your custom logic here
    setCount(count + 1);
  }, 1000); // passing null instead of 1000 will cancel the interval if it is already running

  return <h1>{count}</h1>;
}
// TypeScript Declaration
useInterval(
  callback: () => void,
  delay: number,
  immediate?: boolean /* called when mounted if true */
)

License

MIT


This hook is created using create-react-hook.

Keywords

FAQs

Package last updated on 17 Oct 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc