From e0fe5a913b42e102aa939b38f14a751f30a119b0 Mon Sep 17 00:00:00 2001 From: Dan Brewster Date: Fri, 21 Apr 2023 14:31:41 -0400 Subject: [PATCH] logic: provide result of async call --- ui/src/logic/useAsyncCall.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ui/src/logic/useAsyncCall.ts b/ui/src/logic/useAsyncCall.ts index 63ff02d7..66db161f 100644 --- a/ui/src/logic/useAsyncCall.ts +++ b/ui/src/logic/useAsyncCall.ts @@ -2,8 +2,11 @@ import { useCallback, useState } from 'react'; export type Status = 'initial' | 'loading' | 'success' | 'error'; -export function useAsyncCall(cb: (...args: any[]) => Promise) { +export function useAsyncCall( + cb: (...args: any[]) => Promise +) { const [status, setStatus] = useState('initial'); + const [result, setResult] = useState(null); const [error, setError] = useState(null); const call = useCallback( @@ -11,6 +14,7 @@ export function useAsyncCall(cb: (...args: any[]) => Promise { + setResult(result); setStatus('success'); return result; }) @@ -25,6 +29,7 @@ export function useAsyncCall(cb: (...args: any[]) => Promise