Utility

useDebounce

Debounce rapidly changing values for performance optimization and API calls.

import { useDebounce } from "saha-ui"

Uses

Debounce a value or callback to reduce frequent updates, useful for search inputs or expensive side-effects.

Props

NameTypeDescriptionDefault
valueanyValue to debounce.-
delaynumberDebounce time in milliseconds.-

Returns

NameDescription
debouncedValueValue updated only after the delay has passed.
useDebouncedCallback(callback, delay)Variant that returns a debounced function instead of a value.

Example

const debouncedSearch = useDebounce(searchTerm, 500);
const handle = useDebouncedCallback((term) => fetchResults(term), 500);

Notes

Cleans up timers on unmount; callback variant returns a stable reference.
Saha UI - The Modern React Component Library