Socket
Socket
Sign inDemoInstall

react-timers-hooks

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-timers-hooks

React reusable hooks for Timeout and Interval


Version published
Weekly downloads
384
increased by38.13%
Maintainers
1
Install size
19.0 kB
Created
Weekly downloads
 

Readme

Source

React Timers Hooks npm version License TypeScript

The useInterval/useTimeout custom React hooks accepts 2 arguments - your callback function and delay value which can be a Number or null.

When delay is set to null the timer is cleared, Number value represents timeout in milliseconds.
When delay has changed during the countdown, the tick resets and starts again with new delay value.

Built with TypeScript.

Installation

npm i react-timers-hooks

or

yarn add react-timers-hooks  

Basic usage

import { useInterval, useTimeout } from "react-timers-hooks";

...
useInterval (
    () => {
        doSomething();
    },
    5000
);

useTimeout (
    () => {
        doSomething2();
    },
    2000,
);

Usage with conditionals

import { useInterval, useTimeout } from "react-timers-hooks";

...
const [interval, setInterval] = useState(false);
const [waitAndGo, waitAndGo] = useState(false);

useInterval (
    () => {
        doSomething();
    },
    interval ? 5000 : null,
);

useTimeout (
    () => {
        doSomething2();
    },
    waitAndGo ? 2000 : null,
);

License

MIT

Keywords

FAQs

Last updated on 25 Mar 2022

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