1.1.2 • Published 2 years ago

react-timers-hooks v1.1.2

Weekly downloads
16
License
MIT
Repository
github
Last release
2 years ago

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

1.1.2

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago