mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 01:40:12 +01:00
24 lines
484 B
TypeScript
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;
|