Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// after a delay, keep decrementing at interval ("spinning down")
timeoutRef.current = setTimeout(() => {
setRunOnce(false);
setIsSpinning(true);
setAction("decrement");
}, TIMEOUT_DURATION);
}, [decrement, runOnce]);
// increment using throttle (useful for keydown handlers)
const incrementWithThrottle = throttle(INTERVAL_DURATION, () =>
increment(),
) as VoidFunction;
// decrement using throttle (useful for keydown handlers)
const decrementWithThrottle = throttle(INTERVAL_DURATION, () =>
decrement(),
) as VoidFunction;
// Function to stop spinng (useful for mouseup, keyup handlers)
const stopSpinning = React.useCallback(() => {
setRunOnce(true);
setIsSpinning(false);
removeTimeout();
}, []);
/**
* If the component unmounts while spinning,
* let's clear the timeout as well
*/
React.useEffect(() => {
return () => {