Hooks
useDebounce
A custom React hook for debouncing function calls
Installation
CLI
npx shadcn add https://ui.tiesen.id.vn/r/use-debounce.jsonManual
import * as React from 'react'const useDebounce = <T>(callback: (...args: T[]) => void, delay: number) => { const timeoutRef = React.useRef<NodeJS.Timeout | null>(null) const debouncedCallback = React.useCallback( (...args: T[]) => { if (timeoutRef.current) clearTimeout(timeoutRef.current) timeoutRef.current = setTimeout(() => { // oxlint-disable-next-line promise/prefer-await-to-callbacks callback(...args) }, delay) }, [callback, delay] ) return debouncedCallback}export { useDebounce }