Function
useDebounce
(value: T, delay: number)
Source from the content-addressed store, hash-verified
| 28 | |
| 29 | // Custom hook for debouncing a value |
| 30 | function useDebounce<T>(value: T, delay: number): T { |
| 31 | const [debouncedValue, setDebouncedValue] = useState<T>(value) |
| 32 | |
| 33 | useEffect(() => { |
| 34 | const handler = setTimeout(() => { |
| 35 | setDebouncedValue(value) |
| 36 | }, delay) |
| 37 | |
| 38 | return () => { |
| 39 | clearTimeout(handler) |
| 40 | } |
| 41 | }, [value, delay]) |
| 42 | |
| 43 | return debouncedValue |
| 44 | } |
| 45 | |
| 46 | interface FormData { |
| 47 | type: string |
Tested by
no test coverage detected