plane/web/hooks/use-debounce.tsx
sriram veeraghanta 3ce0aa8ebc restructring
2023-08-22 13:00:23 +05:30

20 lines
426 B
TypeScript

import { useState, useEffect } from "react";
const useDebounce = (value: any, milliSeconds: number) => {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value);
}, milliSeconds);
return () => {
clearTimeout(handler);
};
}, [value, milliSeconds]);
return debouncedValue;
};
export default useDebounce;