All Projects → Hermanya → use-interval

Hermanya / use-interval

Licence: MIT License
⏲ Dan Abramov's interval hook.

Programming Languages

typescript
32286 projects
HTML
75241 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language

use-interval

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

NPM JavaScript Style Guide

Dan Abramov's blog post explaining why you cannot just use setInterval within useEffect.

Used by

Install

npm install --save use-interval

Usage

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>;
}
// TypeScript Declaration
useInterval(
  callback: () => void,
  delay: number,
  immediate?: boolean /* called when mounted if true */
)

License

MIT


This hook is created using create-react-hook.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].