From 01d1dc46888562b86bf20b2d5b7e9371a6760a1a Mon Sep 17 00:00:00 2001 From: NielsJPeschel Date: Fri, 10 Jan 2025 12:48:38 -0500 Subject: [PATCH] simplification --- hooks/useLoadData/useLoadData.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/hooks/useLoadData/useLoadData.ts b/hooks/useLoadData/useLoadData.ts index bb7216a..6d5b7f3 100644 --- a/hooks/useLoadData/useLoadData.ts +++ b/hooks/useLoadData/useLoadData.ts @@ -30,11 +30,11 @@ function unboxApiResponse(arg: ApiResponse | T): T { } } -/* - isPromise determines a promise by checking whether or not it is an instanceof - native promise (preferred) or whether it has a then method. -*/ function isPromise(promisable: Promisable): promisable is Promise { + /* + simply checking promisable instanceof Promise is not sufficient. + Certain environments to not use native promises + */ return promisable && typeof promisable === 'object' && 'then' in promisable && typeof promisable.then === 'function'; } @@ -194,8 +194,7 @@ export function useLoadData( } }, [counter, localFetchWhenDepsChange]); - const initialPromiseRes = initialPromise.res; - const nonPromiseResult = isPromise(initialPromiseRes) ? undefined : initialPromiseRes; + const nonPromiseResult = isPromise(initialPromise.res) ? undefined : initialPromise.res; const initialData = data || nonPromiseResult; // Initialize our pending data to one of three possible states: