Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useDebouncedCallback() has a slightly wrong type #103

Closed
VanTanev opened this issue Mar 29, 2021 · 2 comments
Closed

useDebouncedCallback() has a slightly wrong type #103

VanTanev opened this issue Mar 29, 2021 · 2 comments

Comments

@VanTanev
Copy link

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

@xnimorz
Copy link
Owner

xnimorz commented Mar 29, 2021

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

@xnimorz
Copy link
Owner

xnimorz commented Apr 3, 2021

Published in v.6.0.1 Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment