useDebounce

Hook

Debounces a value. Returns the debounced value after the specified delay.

npx arupui add use-debounce

Usage

use-debounce.tsx
import { useDebounce } from "@/hooks/use-debounce"

function SearchInput() {
  const [query, setQuery] = useState("")
  const debouncedQuery = useDebounce(query, 300)

  useEffect(() => {
    if (debouncedQuery) fetchResults(debouncedQuery)
  }, [debouncedQuery])

  return <input value={query} onChange={(e) => setQuery(e.target.value)} />
}

Parameters

valueT

The value to debounce

delaynumber

Delay in milliseconds

Returns

T
Theme Editor

Theme

Radius0.5rem
Letter Spacing0em

Colors

light