mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
20 lines
426 B
TypeScript
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;
|