interval
v0.0.1arrow_drop_downv0.0.1
STATUS
Passing
DOWNLOADS
274
VISIBILITY
Public
PUBLISHED
6 years ago
SIZE
885 B
1 contributor
Like
Install interval as a package?
Copied
npm i @bit/giladshoham.react-hooks.power-hooks.interval
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
and packages in Bit or NPM to the example. any of the 1 million componentstoggle layout
chevron_left
chevron_right
useInterval
This hook starts an interval timer that can be stopped/resumed any time.
It takes in startImmediate
which decides whether the interval is on by default.
It also takes a time
which is the interval duration.
It provides a start
and stop
method which allow us to control the state of the interval.
Usage
const [time, setTime] = useState(null);
const { start, stop } = useInterval({
duration: 1000,
startImmediate: false,
callback: () => {
setTime(new Date().toLocaleTimeString());
}
});
return (
<Fragment>
<div>The time is now {time}</div>
<button onClick={() => stop()}>Stop interval</button>
<button onClick={() => start()}>Start interval</button>
</Fragment>
);