Skip to content
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

isPending is true with leading: true #192

Open
dborysov opened this issue Jan 3, 2025 · 2 comments
Open

isPending is true with leading: true #192

dborysov opened this issue Jan 3, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@dborysov
Copy link

dborysov commented Jan 3, 2025

Describe the bug
Using useDebounce with leading: true shows that it is pending on the first update

To Reproduce
In the following example:

  const [count, setCount] = useState(0);
  const [countDebounced, { isPending }] = useDebounce(count, 3000, {
    leading: true,
  });

the value of isPending() is true if there was only one update (so the countDebounced is updated immediately)

Steps to reproduce

  1. Open https://codesandbox.io/p/devbox/myd2x2
  2. Click "Increment!" one time
  3. Observe the value under isPending

Expected result:
3. You see false

Actual result:
3. You see true

use-debounce version:
10.0.4

@xnimorz
Copy link
Owner

xnimorz commented Jan 17, 2025

Hello @dborysov

Apologies for the long response.
I opened your example and ran the code, yet I see the value set to false, as intended.

Image

Is there anything I have to change to repro it?

@xnimorz xnimorz added the bug Something isn't working label Jan 17, 2025
@dborysov
Copy link
Author

Hi @xnimorz,

I just went through my initial ticket and realized that it was pretty confusing, sorry for that 🤦‍♂

It's updated now. I added the steps to reproduce. Basically, you need to click the button once and isPending should stay false (since value and debounced are equal immediately), but it becomes true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants