react-dedup-async
Version:
https://www.npmjs.com/package/react-dedup-async
16 lines (14 loc) • 728 B
text/typescript
/**
* React hook to dedupe async calls. The latest args wins.
*
* If idle, it runs the args on the latest callback immediately, returning the promise.
* If busy, it returns a promise that resolves to the next latest call, ignoring all intermediate calls.
*/
declare function useDedupedAsyncCallback<P extends unknown[], R>(fn: (...args: P) => Promise<R>): (...args: P) => Promise<R>;
/**
* React hook to dedupe async calls. Calls while busy are ignored.
*
* If busy, it returns the active promise.
*/
declare function useDedupedAsyncCallbackIgnoreWhileBusy<P extends unknown[], R>(fn: (...args: P) => Promise<R>): (...args: P) => Promise<R>;
export { useDedupedAsyncCallback, useDedupedAsyncCallbackIgnoreWhileBusy };