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

useDebouncedFn clearing timeouts #56

Closed
ayarushin opened this issue Jan 22, 2020 · 5 comments
Closed

useDebouncedFn clearing timeouts #56

ayarushin opened this issue Jan 22, 2020 · 5 comments

Comments

@ayarushin
Copy link
Contributor

Hey,

As I can see you don't use debounced.cancel() here for clearing timeout.
Am I right or I missed something? :)

@antonioru
Copy link
Owner

Hiya @ayarushin
yes, you're right at the moment the useDebouncedFn hook does not return its cancel function, but as it is abstracted on top on Lodash it can easily implemented.
It's a feature I'm open to welcome so if you want to contribute we can discuss how it should be done

A

@ayarushin
Copy link
Contributor Author

Sounds great! I'll do it

@antonioru
Copy link
Owner

antonioru commented Jan 22, 2020

@ayarushin great, man! thank you

Please be sure to return a debounced function to avoid introducing a breaking change also make sure to document how to possibly clear the debounced one.

The lodash approach looks quite good to me, something like:

const debouncedFn = useDebouncedFn(myCallback, 250);

debouncedFn.cancel(); 

@ayarushin
Copy link
Contributor Author

haha, looks like we no need in a fix 😄
i debugged and hook already returns debounced with flush and cancel methods
изображение

@antonioru
Copy link
Owner

antonioru commented Jan 22, 2020

@ayarushin

mmmhhh, that's weird since useCallback shall return a memoized (so a new) version of the function, perhaps it takes care of keeping the static properties somehow.

Anyway, the whole thing still needs to be documented, so feel free to open a PR about that if you want :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants