-
Notifications
You must be signed in to change notification settings - Fork 112
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
add "isPending" to the useDebouncedCallback #61
Comments
Hi @capaj, Thank you for the issue. Talking about Returning So, it seems that we will deoptimize useDebouncedCallback if we include Of course, we are able to add an additional param to the hook, which could turn on Talking about changing the array to an object: it's a good idea, but it requires a major release, so that, we'll make this change as soon as any additional breaking changes will be released. |
isPending could be implemented internally in V4 pretty easily const pending = useCallback(() => {
return timerId.current !== undefined;
}, []);
I've been using a fork of useDebounce at work. Decided to do like like lodash and return the debounced callback but attach the other functions to it: // useDebouncedCallback.tsx
const cancel = useCallback(() => {...});
const flush = useCallback(() => {...});
const pending = useCallback(() => {...});
const debounced = useCallback(() => {...});
debounced.cancel = cancel;
debounced.flush = flush;
debounced.pending = pending;
return debounced;
// MyComponent.tsx
const debounced = useDebouncedCallback(() => {...}, 500);
useEffect(() => {
if (shouldFlush) {
debounced.flush();
}
}, [shouldFlush])
useEffect(() => debounced.cancel, [])
return <button onClick={debounced}>click me</button> Might be one route this lib could go down. |
Hi @capaj ! Published in Also, please take note, that the returning value from |
Thanks. This is great. Closing! |
it would be nice if https://github.com/xnimorz/use-debounce#callpending-method also returned
isPending
.Also since it would return 4 items now, it might make sense to change it into an object. Destructuring an object is fair bit nicer than an array of four items.
The text was updated successfully, but these errors were encountered: