mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
Replaces https://github.com/documenso/documenso/pull/1660 with the same code but targeting our main branch. ## Demo 
16 lines
382 B
TypeScript
16 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;
|
|
};
|