xnimorz / use-debounce

A debounce hook for react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useDebouncedCallback() has a slightly wrong type

VanTanev opened this issue · comments

export interface DebouncedState<T extends (...args: any[]) => ReturnType<T>> extends ControlFunctions {
  (...args: Parameters<T>): ReturnType<T>;
}

Should instead be:

export interface DebouncedState<T extends (...args: any[]) => ReturnType<T>> extends ControlFunctions {
  (...args: Parameters<T>): ReturnType<T> | undefined;
}

The reason is that unless we're invoking on leading edge, the result ref will not be set until the function has been debounced at least once.

Reproduction: https://codesandbox.io/s/use-debounced-callback-return-type-57jme

commented

Thank you, @VanTanev for spotting this!
I'll fix it soon

commented

Published in v.6.0.1 Thanks for reporting!