use-debounce icon indicating copy to clipboard operation
use-debounce copied to clipboard

"leading: true" not working for v7

Open mntnoe opened this issue 3 years ago • 6 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 [email protected]. 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

mntnoe avatar Dec 14 '21 09:12 mntnoe

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

xnimorz avatar Dec 21 '21 11:12 xnimorz

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

xnimorz avatar Feb 12 '22 15:02 xnimorz

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

xnimorz avatar May 01 '22 21:05 xnimorz

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

xnimorz avatar May 01 '22 21:05 xnimorz

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 avatar May 02 '22 09:05 mntnoe

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

xnimorz avatar May 02 '22 10:05 xnimorz

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

xnimorz avatar Aug 28 '22 12:08 xnimorz

I see this as well

franzwarning avatar Oct 03 '23 20:10 franzwarning