use-interval
React hook for setting an interval as posted on overreacted.io
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(() => {
setCount(count + 1);
}, 1000);
return <h1>{count}</h1>;
}
useInterval(
callback: () => void,
delay: number,
immediate?: boolean
)
License
MIT
This hook is created using create-react-hook.