react-hookbox
Version:
react-hookbox is a comprehensive utility hook library for React developers, offering a diverse set of essential hooks to streamline and enhance your development process. Simplify complex tasks, handle common functionalities effortlessly, and boost your pr
17 lines (13 loc) • 381 B
text/typescript
import { useState, useEffect } from 'react'
export const useDebounce = <T>(value: T, delay: number) => {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
return () => {
clearTimeout(handler);
};
}, [value, delay]);
return debouncedValue;
}