@tater-archives/react-use-interval
v1.0.2
Published
React hook to statefully set an interval
Downloads
1
Maintainers
Readme
react-use-interval
React hook to statefully set an interval. Will update when the function updates and has proper cleanup.
Example Usage
useInterval(
// Highly reccommend to use a useCallback hook so that the interval isn't
// changed every single render
useCallback(() => {
console.log('Interval');
// ...
}, []),
1000
);
const [message, setMessage] = useState('Test');
useInterval(
useCallback(() => {
console.log(message);
}, [message]),
60000,
// Determines if the function should run on initialization, otherwise it
// will not run until the first interval
false,
// If resetTimerOnChange is set to true, the timer will reset when the
// function changes
true
);