如果您在 React 应用程序中使用 TanStack Pacer,我们推荐使用 React Adapter。React Adapter 在核心 Pacer 工具之上提供了一组易于使用的 hooks。如果您发现自己想要直接使用核心 Pacer 类/函数,React Adapter 也会重新导出核心包中的所有内容。
npm install @tanstack/react-pacer
npm install @tanstack/react-pacer
请参阅 React 函数参考,查看 React Adapter 中可用的 hooks 的完整列表。
从 React Adapter 导入 react 特定的 hook。
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 类/函数。
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
您的每周 JavaScript 资讯。每周一免费发送给超过 10 万开发者。