🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@rooks/use-timeout

Package Overview
Dependencies
Maintainers
1
Versions
122
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rooks/use-timeout

A React Hooks package for timeout

latest
Source
npmnpm
Version
4.11.2
Version published
Weekly downloads
1.3K
50.18%
Maintainers
1
Weekly downloads
 
Created
Source

@rooks/use-timeout

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

setTimeout hook for react.

Installation

npm install --save @rooks/use-timeout

Importing the hook

import useTimeout from "@rooks/use-timeout"

Usage

function TimeoutComponent() {
  function doAlert() {
    window.alert("timeout expired!");
  }
  const { start, clear } = useTimeout(doAlert, 2000);
  return (
    <>
      <button onClick={start}> Start timeout </button>
      <button onClick={clear}> Clear timeout </button>
    </>
  );
}

render(<TimeoutComponent/>)

Arguments

ArgumentsTypeDescriptionDefault value
callbackfunctionFunction to be executed in timeoutundefind
delayNumberNumber in milliseconds after which callback is to be run0

Returned Object keys

Returned object attributesTypeDescription
clearfunctionClear the timeout
startfunctionStart the timeout
isActivebooleanIs the timeout active

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