New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-useinterval

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-useinterval

A custom React hook that wraps setInterval

1.0.2
latest
Source
npm
Version published
Weekly downloads
5.4K
-12.13%
Maintainers
1
Weekly downloads
 
Created
Source

npm version GitHub license

react-useInterval

A custom React hook that wraps JavaScript's setInterval function.

Install

Install with npm (or yarn):

$ npm install --save react-useinterval

API

useInterval(callback, delay, ...args)

PropertyTypeRequiredDescription
callbackFunctionYesA function to be executed every delay milliseconds.
delayNumber, undefined, or nullNoThe time, in milliseconds, that the timer should delay in between executions of the specified function. Note: If undefined or null is passed, the interval will be paused.
...argsAnyNoAdditional arguments which are passed through to the function specified by callback.

Example Usage

This creates a counter that counts up by five every second.

import React, { useState } from 'react';
import useInterval from 'react-useinterval';

function Counter() {
  let [count, setCount] = useState(0);

  const increaseCount = amount => {
    setCount(count + amount);
  };

  useInterval(increaseCount, 1000, 5);
  return <h1>{count}</h1>;
}

Thanks

Inspired by Dan Abramov's blog post here.

Keywords

react

FAQs

Package last updated on 19 Aug 2020

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