Skip to content

Commit

Permalink
Update use-debounced-callback.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
scamden authored Dec 18, 2024
1 parent b66db88 commit edca32c
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export function useDebounceCallback<T extends (...args: any[]) => any>(
} = useCallback(
(...args: Parameters<T>) => {
window.clearTimeout(debounceTimerRef.current);
const flush = () => handleCallback(...args);
const flush = () => {
if(debounceTimerRef.current !== 0) {
debounceTimerRef.current = 0
handleCallback(...args);
}
}
lastCallback.flush = flush;
debounceTimerRef.current = window.setTimeout(flush, delay);
},
Expand Down

0 comments on commit edca32c

Please sign in to comment.