Skip to content

Commit

Permalink
feat: useDebounce add cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
brickspert committed Aug 19, 2019
1 parent 26cab31 commit 693aec8
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/useDebounce.ts
@@ -1,13 +1,9 @@
import { useCallback, useRef } from 'react';
import useUpdateEffect from './useUpdateEffect';


const useDebounce = (fn: () => any, ms: number = 0, args: any[] = []) => {

const timer = useRef<number>();

useUpdateEffect(() => {

timer.current = window.setTimeout(fn.bind(null, args), ms);
return () => {
// if args change then clear timeout
Expand Down

0 comments on commit 693aec8

Please sign in to comment.