UNPKG

@equinor/fusion-query

Version:

Reactive data fetching and caching library with observable streams and comprehensive event system

38 lines (37 loc) 1.74 kB
import { type UseDebounceOptions } from '@equinor/fusion-observable/react'; import Query, { type QueryCtorOptions } from '../Query'; /** * React hook that creates a debounced query, delaying execution until input stabilizes. * * Accepts either an existing {@link Query} instance or {@link QueryCtorOptions} to create one. * The hook internally binds the query method and applies debounce timing via * {@link UseDebounceOptions}, preventing excessive network requests during rapid input changes * such as search-as-you-type scenarios. * * @template TType - The type of data returned by the query. * @template TArgs - The type of arguments passed to the query function. * * @param clientOrClientCtor - An existing `Query` instance or constructor options to create one. * @param options - Debounce configuration including delay duration and optional leading/trailing flags. * @returns The debounced result from {@link useDebounce}, including the latest value and loading state. * * @example * ```tsx * import { useDebounceQuery } from '@equinor/fusion-query/react'; * * function SearchComponent() { * const [search, setSearch] = useState(''); * const result = useDebounceQuery(myQuery, { * args: [{ search }], * delay: 300, * }); * return <div>{result.value?.name}</div>; * } * ``` */ export declare const useDebounceQuery: <TType, TArgs>(clientOrClientCtor: Query<TType, TArgs> | QueryCtorOptions<TType, TArgs>, options: UseDebounceOptions<[TArgs]>) => { value$: import("rxjs").Observable<import("@equinor/fusion-query").QueryTaskCached<TType> | import("@equinor/fusion-query").QueryTaskCompleted<TType>>; next: (args_0: TArgs) => void; idle: boolean; }; export default useDebounceQuery;