Skip to content
Dan Abramov's interval hook.
TypeScript HTML JavaScript CSS
Branch: master
Clone or download
Latest commit 07a6188 Feb 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example
src minor fixes Feb 21, 2019
.editorconfig init create-react-hook@2.6.15 Feb 4, 2019
.gitignore add tests Feb 21, 2019
.prettierrc get 100% coverage Feb 21, 2019
.travis.yml init create-react-hook@2.6.15 Feb 4, 2019
LICENSE add LICENSE file (MIT) Feb 21, 2019
README.md add immediate mode Feb 21, 2019
package.json 1.1.0 Feb 21, 2019
rollup.config.js fix TypeScript configuration Feb 21, 2019
tsconfig.json fix TypeScript configuration Feb 21, 2019
yarn.lock minor fixes Feb 21, 2019

README.md

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.

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);

  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.

You can’t perform that action at this time.