框架
版本
防抖器 API 参考
节流器 API 参考
速率限制器 API 参考
队列 API 参考
批处理器 API 参考

TanStack Pacer React Adapter

如果您在 React 应用程序中使用 TanStack Pacer,我们推荐使用 React Adapter。React Adapter 在核心 Pacer 工具之上提供了一组易于使用的 hooks。如果您发现自己想要直接使用核心 Pacer 类/函数,React Adapter 也会重新导出核心包中的所有内容。

安装

sh
npm install @tanstack/react-pacer
npm install @tanstack/react-pacer

React Hooks

请参阅 React 函数参考,查看 React Adapter 中可用的 hooks 的完整列表。

基本用法

从 React Adapter 导入 react 特定的 hook。

tsx
import { useDebouncedValue } from '@tanstack/react-pacer'

const [instantValue, instantValueRef] = useState(0)
const [debouncedValue, debouncer] = useDebouncedValue(instantValue, {
  wait: 1000,
})
import { useDebouncedValue } from '@tanstack/react-pacer'

const [instantValue, instantValueRef] = useState(0)
const [debouncedValue, debouncer] = useDebouncedValue(instantValue, {
  wait: 1000,
})

或者从 React Adapter 重新导出的核心 Pacer 类/函数。

tsx
import { debounce, Debouncer } from '@tanstack/react-pacer' // no need to install the core package separately
import { debounce, Debouncer } from '@tanstack/react-pacer' // no need to install the core package separately
我们的合作伙伴
Code Rabbit
Unkey
订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。

订阅 Bytes

您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。

Bytes

无垃圾邮件。您可以随时取消订阅。