xnimorz/use-debounce

"leading: true" not working for v7

mntnoe opened this issue · 8 comments

Describe the bug
For the versions 7.0.0 and 7.0.1, setting { leading: true } does not trigger an immediate change in useDebounce. It works in 6.0.1 and below.

To Reproduce

  • The sandbox example linked to in the readme file (https://codesandbox.io/s/rr40wnropq) uses use-debounce@6.0.0-beta. Add the option { leading: true } and observe that the debounced value is updated immedately for the first change.
  • Change the version number to 7.0.0 or 7.0.1, and observe that the behavior is now as if { leading: true } is not given.

Expected behavior
Setting { leading: true } should trigger immediately for the first change, and subsequently trigger immediately on changes after the wait timeout has expired.

use-debounce version:
7.0.0 and 7.0.1

Hey, thank you for reporting the issue.
You're welcome to open the PR to fix it!

Labelling it as a good for new contributors, who are looking for possibilities to start with open source

Hey @mntnoe
I've published v8.0.0 of the library.

Now it works with leading: true correctly, here is the demo:

https://codesandbox.io/s/cache-example-with-areas-and-leading-param-119r3i

If you get any issues during the update from 7.x.x => 8.x.x here is a guidance: https://github.com/xnimorz/use-debounce/blob/master/CHANGELOG.md#800

I'm closing this issue as it should be resolved for now. Please, feel free to re-open it if you still get any issues with it

Thank you for looking into this. When using { leading: true }, we get some strange behavior in our code with v8.0.0, where the new value is used initially, but then reverted:

VALUE  DEBOUNCED
a      a
b      a
b      b
bb     a
bbb    a
bbb    bbb

I'll try to investigate what happens when I get time.

@mntnoe interesting, thanks, I'll try to reproduce it too.

I cannot repro it now. If you have an example, please share it. I'll close the issue for now

I see this as well