/react-use-interval

React utility hook for managing intervals.

Primary LanguageTypeScriptMIT LicenseMIT

Blazing Fast license

react-use-interval

This is an customized version of the react hook for setting an interval as posted on overreacted.io.

Install

npm install --save @ascendum/use-interval

Usage

import as React from 'react'

import { useInterval } from 'react-use-interval'

const MyComponent = () => {
  const {
    toggleRunning,
    isRunning
  } = useInterval(() => {
    // Do whatever magic you wish here.
  }, 1000);

  return (
    <div>
      <button onClick={toggleRunning}>
        {isRunning ? 'Paused' : 'Resume'}
      </button>
    </div>
  );
}

License

MIT