-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
use-throttled-value does not always issue an update with the last value #6220
Comments
I'm not really sure how this would make the hooks different from debounce hooks |
The debounced hooks emit updates only after the data source has settled down. It does not have a leading edge and the emitted update can be postponed indefinitely, as long as the data source keeps changing. This is useful for search boxes, when a request should only be sent, when the user has stopped typing. Here is the behavior using the examples in the documentation: Debounced: value: 'abc' (typing 'a', 'b', 'c') Throttled (old): value: 'abc' (typing 'a', 'b', 'c') Throttled (new): value: 'abc' (typing 'a', 'b', 'c') |
Okay, I'm fine with these changes, you are welcome to submit a PR |
In lodash |
That would be a nicer solution. My PR does not include such a options, though. |
Dependencies check up
What version of @mantine/* packages do you have in package.json?
7.9.0
What package has an issue?
@mantine/hooks
What framework do you use?
Vite
In which browsers you can reproduce the issue?
All
Describe the bug
Currently
useThrottledValue
(and the other throttled hooks) don't emit an update for the last value change if that change occurred while the timer was active.lodash
calls this the trailing edge [1].Ideally the hooks would support arguments to configure this behavior. But in absence of such arguments, I think emitting on the trailing edge is the more intuitive behavior.
I changed the implementation of
useThrottledValue
to fit my need.Let me know if you are interested in a PR. You may also just take my code if you want to.
[1] https://lodash.com/docs/4.17.15#throttle
If possible, include a link to a codesandbox with a minimal reproduction
No response
Possible fix
Self-service
The text was updated successfully, but these errors were encountered: