mirror of
https://github.com/documenso/documenso
synced 2026-05-01 18:07:19 +00:00
Replaces https://github.com/documenso/documenso/pull/1660 with the same code but targeting our main branch. ## Demo 
15 lines
382 B
TypeScript
15 lines
382 B
TypeScript
import React, { useEffect } from 'react';
|
|
|
|
export const useDebounce = <T>(value: T, delay?: number): T => {
|
|
const [debouncedValue, setDebouncedValue] = React.useState<T>(value);
|
|
|
|
useEffect(() => {
|
|
const timer = setTimeout(() => setDebouncedValue(value), delay || 500);
|
|
|
|
return () => {
|
|
clearTimeout(timer);
|
|
};
|
|
}, [value, delay]);
|
|
|
|
return debouncedValue;
|
|
};
|