Skip to content

Ensure useDebounceCallback flushes on dep change or unmount #686

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Aleuck
Copy link

@Aleuck Aleuck commented Apr 7, 2025

I believe this is an important improvement to make sure pending debounced invocations are called right before unmounting or dependency changes to the hook.

Someone might want them to be cancelled in these cases instead, but I think the general expectation is that if you make a call to a debounced function, it will eventually be invoked.

If the needs arise, we could add a new boolean option or a union type:

type AdditionalOptions = {
  cancelOnCleanup: boolean; // or
  cleanupBehavior: 'flush' | 'cancel' | 'none';
}

Copy link

changeset-bot bot commented Apr 7, 2025

🦋 Changeset detected

Latest commit: 38525bb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
usehooks-ts Patch
www Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Aleuck Aleuck changed the title Ensure useDebounceCallback flushes on dep change or unmount; Ensure useDebounceCallback flushes on dep change or unmount Apr 7, 2025
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

Successfully merging this pull request may close these issues.

1 participant