Skip to content

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