import type { DependencyList } from 'react'; export type IRequestStatus = 'NONE' | 'PENDING' | 'REJECTED' | 'RESOLVED'; export interface IUseLatestPromiseResult { result: T; status: IRequestStatus; error: any; refresh: () => void; requestId: number; } /** * A react hook which invokes a callback that returns a promise. * If multiple requests are made concurrently, only returns data from the latest request. * * This can be useful when fetching data based on a users keyboard input, for example. * This behavior is similar to RxJS switchMap. * * example: * const fetch = useLatestPromise(() => fetch(url + '?foo=" + foo).then(x=>x.json()), [foo]); * return (fetch.status === 'RESOLVED' ?
{JSON.stringify(fetch.result, null, 2)}
: * fetch.status === 'REJECTED' ? Error: {fetch.error} : * fetch.status === 'PENDING' ? Loading... : null); * * @param callback a callback that returns a PromiseLike * @param deps array of dependencies, which (when changed) cause the callback to be invoked again * @returns an object with the result and current status of the promise */ export declare function useLatestPromise(callback: () => PromiseLike, deps: DependencyList): IUseLatestPromiseResult;