# use-interval

> React hook for setting an interval as posted on overreacted.io

Latest version **1.4.0** (published 2021-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-interval
pnpm add use-interval
yarn add use-interval
bun add use-interval
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2021-10-17 |
| First published | 2019-02-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Hermanya |
| Maintainers | hermanya |
| Keywords | react, hook, interval, setInterval |

## Links

- npm: https://www.npmjs.com/package/use-interval
- Repository: https://github.com/Hermanya/use-interval
- Homepage: https://github.com/Hermanya/use-interval#readme
- Issues: https://github.com/Hermanya/use-interval/issues
- npm.io page: https://npm.io/package/use-interval

## 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

- 1.4.0 (latest) — 2021-10-17
- 1.3.0 — 2020-09-13
- 1.2.1 — 2019-12-06
- 1.2.0 — 2019-12-05
- 1.1.0 — 2019-02-21
- 1.0.3 — 2019-02-04
- 1.0.2 — 2019-02-04
- 1.0.1 — 2019-02-04
- 1.0.0 — 2019-02-04

## README

# use-interval

> React hook for setting an interval as posted on overreacted.io

[![NPM](https://img.shields.io/npm/v/use-interval.svg)](https://www.npmjs.com/package/use-interval) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

[Dan Abramov's blog post explaining why you cannot just use `setInterval` within `useEffect`.](https://overreacted.io/making-setinterval-declarative-with-react-hooks/)

## Used by


- [codesandbox / codesandbox-client](https://github.com/codesandbox/codesandbox-client)
- [kentcdodds / react-performance](https://github.com/kentcdodds/react-performance)
- [siddharthkp / react-ui](https://github.com/siddharthkp/react-ui)
- [element-motion](https://github.com/element-motion/element-motion)
- [wintercounter / mhy](https://github.com/wintercounter/mhy)
- [sagemathinc / cocalc](https://github.com/sagemathinc/cocalc)
- [wintercounter / mhy](https://github.com/wintercounter/mhy)

## Install

```bash
npm install --save use-interval
```

## Usage

```tsx
import * as React from 'react'

import useInterval from 'use-interval'

const Example = () => {
  let [count, setCount] = React.useState(0);

  useInterval(() => {
    // Your custom logic here
    setCount(count + 1);
  }, 1000); // passing null instead of 1000 will cancel the interval if it is already running

  return <h1>{count}</h1>;
}
```

```tsx
// TypeScript Declaration
useInterval(
  callback: () => void,
  delay: number,
  immediate?: boolean /* called when mounted if true */
)
```

## License

MIT

---

This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).

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