-
Notifications
You must be signed in to change notification settings - Fork 99
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
useDebouncedCallback will miss the trailing call when when maxWait is set #1357
Comments
@xobotyi Any idea on why we have used If we use code for |
Mostly because crapton of code to make raf work like timeout. moreover i dont think that it is right solution to make debounce use raf in order to make it work, because in case of RAF usage and, say, debounce set to 500ms and debounce function called once - raf callback would be called 30 times before debounced function invocation - it is huge overhead in my eyes. |
ookay, dug into the problem, reason is quiet simple - |
🎉 This issue has been resolved in version 24.0.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
What is the current behavior?
What does
@react-hookz/web
do right now.When I set a maxWait in useDebouncedCallback, it will drop the triling call.
Steps to Reproduce
https://codesandbox.io/s/usedebouncedcallback-bug-gj69sg?file=%2Fsrc%2Fuse-debounce-demo.tsx
The codesandbox has two implementation of counter, and a log in useEffect. One use
@react-hookz/web
, the other use theuse-debounce
package.You can click the two button quickly in a short time. You can see the log is mismatch with the actual final state in the react-hookz one , beacause the trailling call is drop when maxWait is set.
What is the expected behavior?
Give a options to enabled traling call or add traling call by default like lodash.
What should
@react-hookz/web
be doing?https://github.com/react-hookz/web/blob/master/src/useDebouncedCallback/index.ts#L34 Maybe maxWait excute should not clear waitTimeout.
Environment Details
@react-hookz/web
version: 23.0.0react
version: 18.2.0react-dom
version: 18.2.0typescript
version: 4.4.2The text was updated successfully, but these errors were encountered: