@lido-sdk/react
Version:
This project is being slowly deprecated and may not receive further updates. Check out [modern Lido SDK](https://github.com/lidofinance/lido-ethereum-sdk/pulls) to access latest functionality. It is actively maintained and is built for interacting with Li
20 lines (17 loc) • 559 B
JavaScript
import { useRef, useCallback, useEffect } from 'react';
const useDebounceCallback = (callback, timeout = 0) => {
const timer = useRef(null);
const clearTimer = useCallback(() => {
if (timer.current != null) {
clearTimeout(timer.current);
}
}, []);
useEffect(() => {
return clearTimer;
}, [clearTimer]);
return useCallback(() => {
clearTimer();
timer.current = setTimeout(callback, timeout);
}, [callback, timeout, clearTimer]);
};
export { useDebounceCallback };