New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@rooks/use-interval

Package Overview
Dependencies
Maintainers
1
Versions
121
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rooks/use-interval

A react hook for using setInterval

latest
Source
npmnpm
Version
4.11.2
Version published
Weekly downloads
2.1K
-10.54%
Maintainers
1
Weekly downloads
 
Created
Source

@rooks/use-interval

Note: Future updates to this package have moved to the main package rooks. All hooks now reside in a single package which you can install using

npm install rooks

or

yarn add rooks

Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!

TitleCard

Build Status

About

setInterval hook for React.

Installation

npm install --save @rooks/use-interval

Importing the hook

import useInterval from "@rooks/use-interval"

Usage

function reducer(state, action) {
  switch (action.type) {
    case "increment":
      return { count: state.count + 1 };
    default:
      return state;
  }
}

function Demo() {
  const [value, dispatcher] = useReducer(reducer, { count: 0 });

  function increment() {
    dispatcher({
      type: "increment"
    });
  }

  const { start, stop } = useInterval(() => {
    increment();
  }, 1000);

  return (
    <>
      <p>value is {value.count}</p>
      <button onClick={start}>Start</button>
      <button onClick={stop}>Stop</button>
    </>
  );
}
render(<Demo/>)

Arguments

ArgumentTypeDescriptionDefault value
callbackfunctionFunction be invoked after each interval durationundefined
intervalDurationnumberDuration in milliseconds after which callback is invokedundefined
startImmediatebooleanShould the timer start immediately or nofalse

Returned Object

Returned object attributesTypeDescription
startfunctionStart the interval
stopfunctionStop the interval
intervalIdintervalIdIntervalId of the interval

Keywords

use

FAQs

Package last updated on 01 May 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