# @rooks/use-timeout

> A React Hooks package for timeout

Latest version **4.11.2** (published 2021-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rooks/use-timeout
pnpm add @rooks/use-timeout
yarn add @rooks/use-timeout
bun add @rooks/use-timeout
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.11.2 |
| Published | 2021-05-01 |
| First published | 2018-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3451 |
| Maintainers | imbhargav5 |
| Keywords | use, react-hooks.org, react, hooks, rooks, timeout, timeout hook |

## Links

- npm: https://www.npmjs.com/package/@rooks/use-timeout
- Repository: https://github.com/imbhargav5/rooks
- Homepage: https://react-hooks.org/docs/use-timeout
- Issues: https://github.com/imbhargav5/rooks/issues
- npm.io page: https://npm.io/package/@rooks/use-timeout

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.11.2 (latest) — 2021-05-01
- 4.9.0-canary.0 (canary) — 2021-02-10
- 3.4.4-71d48a96.0 (next) — 2019-12-14
- 3.4.2-0668aca8.0 (dev) — 2019-12-04
- 3.3.0-alpha.0 (alpha) — 2019-09-07
- 3.0.3-alpha.0 (beta) — 2019-06-09
- 1.1.5-alpha.1 (remove-readme) — 2019-01-27
- 4.11.1 — 2021-05-01
- 4.11.0 — 2021-04-06
- 4.10.1 — 2021-03-31
- 4.10.0 — 2021-03-21
- 4.9.2 — 2021-02-21
- 4.9.1 — 2021-02-11
- 4.9.0 — 2021-02-10
- 4.8.1 — 2021-02-03
- … 107 more at https://npm.io/package/@rooks/use-timeout/versions

## README

# @rooks/use-timeout

## *Note: Future updates to this package have moved to the main package* [rooks](https://npmjs.com/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](https://raw.githubusercontent.com/imbhargav5/rooks/v4-compat/packages/timeout/title-card.svg)

![Build Status](https://github.com/imbhargav5/rooks/workflows/Node%20CI/badge.svg)![](https://img.shields.io/npm/v/@rooks/use-timeout/latest.svg) ![](https://img.shields.io/npm/l/@rooks/use-timeout.svg) ![](https://img.shields.io/npm/dt/@rooks/use-timeout.svg) ![](https://img.shields.io/david/imbhargav5/rooks.svg?path=packages%2Ftimeout)




## About 
setTimeout hook for react.
<br/>

## Installation

```
npm install --save @rooks/use-timeout
```

## Importing the hook

```javascript
import useTimeout from "@rooks/use-timeout"
```


## Usage

```jsx
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

| Arguments | Type     | Description                                              | Default value |
| --------- | -------- | -------------------------------------------------------- | ------------- |
| callback  | function | Function to be executed in timeout                       | undefind      |
| delay     | Number   | Number in milliseconds after which callback is to be run | 0             |

### Returned Object keys

| Returned object attributes | Type     | Description           |
| -------------------------- | -------- | --------------------- |
| clear                      | function | Clear the timeout     |
| start                      | function | Start the timeout     |
| isActive                   | boolean  | Is the timeout active |

---
_Source: https://npm.io/package/@rooks/use-timeout · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
