BlueWallet/hooks/useDebounce.ts
Marcos Rodriguez Velez 02519bce91
ADD: useDebounce hook
2024-05-25 12:33:21 -04:00

24 lines
484 B
TypeScript

import { useState, useEffect } from 'react';
import debounce from '../blue_modules/debounce';
const useDebounce = <T>(value: T, delay: number): T => {
const [debouncedValue, setDebouncedValue] = useState<T>(value);
useEffect(() => {
const handler = debounce((val: T) => {
setDebouncedValue(val);
}, delay);
handler(value);
return () => {
handler.cancel();
};
}, [value, delay]);
return debouncedValue;
};
export default useDebounce;