Skip to content

Commit

Permalink
Add usePromise documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet committed Nov 2, 2023
1 parent 1570308 commit 96259f7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/hooks/usePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ type PromiseState<T> = {
reason?: Error;
};

/**
* Returns a promise state object to track the provided `promise`.
* Ignores outdated promises or ones that resolve when the component got unmounted.
*
* @param promise The promise to track.
* @returns A promise state object
*/
export function usePromise<T>(promise?: Promise<T> | T) {
const { 0: state, 1: onChangeState } = useState<PromiseState<T>>({
status: "idle",
Expand Down

0 comments on commit 96259f7

Please sign in to comment.