Skip to content

Commit

Permalink
simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsJPeschel committed Jan 10, 2025
1 parent 321caef commit 01d1dc4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions hooks/useLoadData/useLoadData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function unboxApiResponse<T>(arg: ApiResponse<T> | 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<T>(promisable: Promisable<T>): promisable is Promise<T> {
/*
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';
}

Expand Down Expand Up @@ -194,8 +194,7 @@ export function useLoadData<T extends NotUndefined, Deps extends any[]>(
}
}, [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:
Expand Down

0 comments on commit 01d1dc4

Please sign in to comment.