useDebounceValue

Custom hook that returns a debounced version of the provided value, along with a function to update it.

Custom hook that returns a debounced version of the provided value, along with a function to update it.

Usage

import { useDebounceValue } from "@tilt-legal/cubitt-components/utilities/hooks";

const [debouncedValue, updateDebouncedValue] = useDebounceValue(inputValue, 500, { leading: true });

API

Signature

declare function useDebounceValue<T>(initialValue: T | (() => T), delay: number, options?: UseDebounceValueOptions<T>): [T, DebouncedState<(value: T) => void>];

Parameters

ParameterTypeDescriptionDefault
initialValue`T(() => T)`The value to be debounced.
delaynumberThe delay in milliseconds before the value is updated (default is 500ms).-
[options]objectOptional configurations for the debouncing behavior.-

Return Value

ValueTypeDescription
return[T, DebouncedState&lt;(value: T) =&gt; void&gt;]An array containing the debounced value and the function to update it.

On this page