dev: useApi accepts ApiCallOptions

Massimo Melina committed Oct 3, 2023 at 23:54 UTC 179772bdcf29d21bf41bf3537a03b225c4365d03
1 file changed +2 -2
shared/api.ts
+2 -2
@@ -71,7 +71,7 @@ export class ApiError extends Error {
71 }
72 }
73
74 -export function useApi<T=any>(cmd: string | Falsy, params?: object) {
74 +export function useApi<T=any>(cmd: string | Falsy, params?: object, options: ApiCallOptions={}) {
75 const [data, setData] = useStateMounted<T | undefined>(undefined)
76 const [error, setError] = useStateMounted<Error | undefined>(undefined)
77 const [forcer, setForcer] = useStateMounted(0)
@@ -85,7 +85,7 @@ export function useApi<T=any>(cmd: string | Falsy, params?: object) {
85 let aborted = false
86 let req: undefined | ReturnType<typeof apiCall>
87 const wholePromise = wait(0) // postpone a bit, so that if it is aborted immediately, it is never really fired (happens mostly in dev mode)
88 - .then(() => aborted ? undefined : req = apiCall<T>(cmd, params))
88 + .then(() => aborted ? undefined : req = apiCall<T>(cmd, params, options))
89 .then(res => aborted || setData(res), err => aborted || setError(err) || setData(undefined))
90 .finally(() => loadingRef.current = reloadingRef.current = undefined)
91 loadingRef.current = Object.assign(wholePromise, {