xnimorz/use-debounce

useDebouncedCallback() has a slightly wrong type

VanTanev opened this issue · 2 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

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

Published in v.6.0.1 Thanks for reporting!