mirror of
https://github.com/streamich/react-use.git
synced 2026-01-25 14:17:16 +00:00
15 lines
340 B
TypeScript
15 lines
340 B
TypeScript
import { DependencyList } from 'react';
|
|
import useUpdateEffect from './useUpdateEffect';
|
|
|
|
const useDebounce = (fn: () => any, ms: number = 0, deps: DependencyList = []) => {
|
|
useUpdateEffect(() => {
|
|
const timeout = setTimeout(fn, ms);
|
|
|
|
return () => {
|
|
clearTimeout(timeout);
|
|
};
|
|
}, deps);
|
|
};
|
|
|
|
export default useDebounce;
|