import { CancellablePromise } from 'real-cancellable-promise'; export interface UseSimpleQueryProps { queryParams: TQueryParams; query(queryParams: TQueryParams): CancellablePromise; shouldQueryImmediately(prevQueryParams: TQueryParams, queryParams: TQueryParams): boolean; onResultReceived(result: TResult): void; onLoadingChange?(loading: boolean): void; onError?(e: unknown): void; debounceDelay?: number; onQueryStarted?(): void; /** Useful in uncommon scenarios to prevent unnecessary asynchronous updates to a component */ shouldSkipQuery?(queryParams: TQueryParams): boolean; } export interface UseSimpleQueryReturn { doQuery(options?: { changeLoading: boolean; }): void; doQueryAsync(options?: { changeLoading: boolean; }): Promise; } /** * @deprecated Except for use by `useAsyncValidator`. * * Perform a query on mount and whenever `queryParams` change. * * - `queryParams`: must be referentially stable, otherwise there will be an infinite * loop. `useMemo` is helpful here. * - `query`: must be not depend on outside variables, e.g. props!!! Changing `query` does * not cause the query to rerun. * - `shouldQueryImmediately`: provide a function here that takes in the previous query params * and the current query params and return false if you want debouncing to occur. * - `onError`: only needs to be provided if this query has custom error-handling logic. * If not provided, the `onError` from `ItiReactCoreContext` will be used. * * Example: * ``` * const { doQuery, doQueryAsync } = useSimpleQuery({ * queryParams: workDocId, * query: (id) => api.workDoc.get({ id }), * shouldQueryImmediately: (prev, cur) => true, * onResultReceived: (workDoc) => { * setWorkDoc(workDoc) * } * }) * ``` * * @typeParam TQueryParams the parameters of the query * @typeParam TResult the type returned by the query * * @returns an object containing `doQuery` and `doQueryAsync` functions. `doQueryAsync` * must be called within a `try-catch`. */ export declare function useSimpleQuery(props: UseSimpleQueryProps): UseSimpleQueryReturn;