Loading...
Loading...
Compare original and translation side by side
setTimeoutsetTimeout| Pattern | API | Key Points |
|---|---|---|
| Debounce function | | Waits for inactivity; no |
| Throttle function | | Even spacing; |
| Rate limit | | Fixed or sliding window; rejects calls over limit |
| Queue items | | FIFO default; supports LIFO, priority, expiration |
| Async queue | | Concurrency control, retry, error callbacks |
| Async batch | | Collects items, processes as batch after wait/maxSize |
| React debounce | | Instance hook vs simple callback hook |
| React throttle | | Instance hook vs simple callback hook |
| React rate limit | | Instance hook vs simple callback hook |
| React queue | | Instance hook vs state-integrated hook |
| React async queue | | Concurrency + state management |
| React batch | | Sync and async batching hooks |
| State hooks | | Integrate with React state directly |
| Value hooks | | Create derived debounced/throttled values |
| 模式 | API | 核心要点 |
|---|---|---|
| 防抖函数 | | 等待无活动状态;设计上默认无 |
| 节流函数 | | 均匀间隔执行; |
| 速率限制 | | 固定或滑动窗口;超出限制时拒绝调用 |
| 任务排队 | | 默认先进先出;支持后进先出、优先级、过期机制 |
| 异步任务队列 | | 并发控制、重试、错误回调 |
| 异步批处理 | | 收集任务项,在等待超时或达到最大数量后批量处理 |
| React 防抖 | | 实例钩子 vs 简单回调钩子 |
| React 节流 | | 实例钩子 vs 简单回调钩子 |
| React 速率限制 | | 实例钩子 vs 简单回调钩子 |
| React 任务队列 | | 实例钩子 vs 集成状态的钩子 |
| React 异步任务队列 | | 并发控制 + 状态管理 |
| React 批处理 | | 同步和异步批处理钩子 |
| 状态钩子 | | 直接与React状态集成 |
| 值钩子 | | 创建派生的防抖/节流值 |
| Mistake | Correct Pattern |
|---|---|
Using | Debouncer has no |
| Creating instances inside render | Create with hooks ( |
Ignoring | Rate limiter and throttler may reject calls; check state or use callbacks |
| Using debounce when throttle is needed | Debounce waits for pause; throttle guarantees max-once-per-interval |
| Not cleaning up on unmount | React hooks handle cleanup automatically; manual instances need |
| Using Queuer when items can be dropped | Queuers process every item; use throttle/debounce if dropping is acceptable |
| Fixed window when sliding is needed | Fixed windows allow bursts at boundaries; sliding window gives smoother rate |
Forgetting | Rejected calls are silent by default; add |
Not passing | All utilities support |
| 错误操作 | 正确做法 |
|---|---|
在Debouncer中使用 | Debouncer 无 |
| 在渲染内部创建实例 | 使用钩子( |
忽略 | 速率限制器和节流器可能会拒绝调用;请检查状态或使用回调函数 |
| 需要节流时使用了防抖 | 防抖会等待操作暂停;节流可保证每间隔最多执行一次 |
| 组件卸载时未清理资源 | React钩子会自动处理清理;手动创建的实例需要调用 |
| 可丢弃任务时使用Queuer | Queuer会处理每个任务项;若可丢弃任务,请使用节流/防抖 |
| 需要滑动窗口时使用了固定窗口 | 固定窗口允许在边界处出现突发请求;滑动窗口可提供更平滑的速率控制 |
忘记为RateLimiter添加 | 默认情况下被拒绝的调用无提示;请添加 |
未通过 | 所有工具均支持 |
If theskill is available, delegate data fetching and cache management tasks to it. TanStack Pacer complements Query for controlling request frequency. Otherwise, recommend:tanstack-querynpx skills add oakoss/agent-skills --skill tanstack-query
tanstack-query若技能可用,请将数据获取和缓存管理任务委托给它。TanStack Pacer 可与Query配合使用,控制请求频率。 否则,推荐执行:tanstack-querynpx skills add oakoss/agent-skills --skill tanstack-query
tanstack-query