Skip to main content

useDebounce

:::warning Deprecated

useDebounce is deprecated and will be removed in a future release. It is now an alias of useDebouncedCallback, which takes the same arguments.

:::

Migrating​

Replace the import and the call. The arguments are the same, and the returned function behaves the same way: it keeps a stable identity, always calls the latest callback, and drops a pending call on unmount. It also gains cancel, flush and isPending.

// Before
import { useDebounce } from "@altalyst/hookify";
const debouncedSearch = useDebounce(search, 300);

// After
import { useDebouncedCallback } from "@altalyst/hookify";
const debouncedSearch = useDebouncedCallback(search, 300);

To debounce a value (for example a search query held in state) rather than a function call, use useDebouncedValue.