Skip to content

Commit

Permalink
Do not send abort event in usePromise when promise has already finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Sep 10, 2024
1 parent bff3bd8 commit 0eb1ba4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions js/api/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export function usePromise<T extends (...args: any[]) => Promise<any>, R>(
if (promise === promiseRef.current) {
setState({ error, isLoading: false })

if (options && options.abortable) {
options.abortable.current = undefined;
}

options?.onError?.(error);
}
return
Expand All @@ -105,6 +109,10 @@ export function usePromise<T extends (...args: any[]) => Promise<any>, R>(
if (promise === promiseRef.current) {
setState({ data: promiseResult, isLoading: false });

if (options && options.abortable) {
options.abortable.current = undefined;
}

options?.onData?.(promiseResult)
}
}, args || []);
Expand Down

0 comments on commit 0eb1ba4

Please sign in to comment.