Skip to content

Commit

Permalink
fix: useDebounce remove deps from function arguments (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardoost committed Sep 26, 2019
1 parent 8c0d178 commit 23d6a5a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/useDebounce.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { DependencyList } from 'react';
import useUpdateEffect from './useUpdateEffect';

const useDebounce = (fn: () => any, ms: number = 0, args: any[] = []) => {
const useDebounce = (fn: () => any, ms: number = 0, deps: DependencyList = []) => {
useUpdateEffect(() => {
const handle = setTimeout(fn.bind(null, args), ms);
const timeout = setTimeout(fn, ms);

return () => {
// if args change then clear timeout
clearTimeout(handle);
clearTimeout(timeout);
};
}, args);
}, deps);
};

export default useDebounce;

0 comments on commit 23d6a5a

Please sign in to comment.