Would be great to configure trailing
Closed this issue ยท 7 comments
Lodash's implementation of debounce has a trailing option which is necessary to specify in some cases: https://lodash.com/docs/4.17.15#debounce
It would be nice to have that option for this library.
Hello @scottmas
Thank you for the issue.
It would be great if you show the use case of such usage.
Btw, you are welcome to PR :)
The use case is basically e.g. liking a post.
Someone clicks between 1 time or 5 times in a row. You update the UI accordingly in real time, but you want to make sure that the mutation query captures the final state and executes once.
Hi, thank you.
Yes, it could be good.
At the moment, I don't have enough time, but you can send a PR :)
Or I'll add it when I get some free time.
The use case is basically e.g. liking a post.
Someone clicks between 1 time or 5 times in a row. You update the UI accordingly in real time, but you want to make sure that the mutation query captures the final state and executes once.
Would you be able to use "leading" instead? What's the practical difference?
It would be great if you show the use case of such usage.
Prevent doubleClick
, not all web users understand that browsers require a single click for their actions. We see double click's happen quite often, resulting in actions directly being undone
when calling a toggle
handler.
lodash.debounce(myFn, 500, { leading: true, trailing: false })
filters out the double click, without adding a delay for the first click. I use 500ms, because that's what Windows uses as the double click threshold.
Would love this for my use case as well.
Hi!
I've published use-debounce@3.3.0
which has both leading
and trailing
options. They work like similar lodash params, you can find examples and try it in this playground: https://codesandbox.io/s/vigilant-bush-zrbzg
By default leading
is false, and trailing
is true.