mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
15 lines
331 B
TypeScript
15 lines
331 B
TypeScript
import { useEffect } from 'react';
|
|
|
|
const useDebounce = (fn: () => any, ms: number = 0, args: Array<any> = []) => {
|
|
useEffect(() => {
|
|
let handle = setTimeout(fn.bind(null, args), ms);
|
|
|
|
return () => {
|
|
// if args change then clear timeout
|
|
clearTimeout(handle);
|
|
}
|
|
}, args);
|
|
};
|
|
|
|
export default useDebounce;
|