hooks icon indicating copy to clipboard operation
hooks copied to clipboard

feature: The throttle function should remove the default 1000 milliseconds to support the use of requestAnimationFrame

Open zhe-he opened this issue 1 year ago • 2 comments

Hello, I have a requirement in my React project to throttle using requestAnimationFrame. I noticed that lodash natively supports it, but ahooks has added extra logic to set a default time of 1000 milliseconds. Here are the links to the two relevant source code sections:

  1. Lodash throttle source code
  2. ahooks source code

zhe-he avatar Sep 26 '23 02:09 zhe-he

你可以把 wait 设置为 0 来实现你的需求

crazylxr avatar Feb 27 '24 02:02 crazylxr

https://github.com/lodash/lodash/blob/main/src/debounce.ts#L77-L78

image

@crazylxr 见哥,这里 wait 设置 0 恰好是绕过 requestAnimationFrame,需要 ahooks 支持用户设置 wait 为 undefined 来启用 requestAnimationFrame 的,你再看下呢~

liuyib avatar Feb 27 '24 03:02 liuyib

solved: https://github.com/alibaba/hooks/pull/2332

liuyib avatar Apr 23 '24 02:04 liuyib