Skip to content
Snippets Groups Projects
Commit 99bf0164 authored by Maxime Jacquemin's avatar Maxime Jacquemin
Browse files

[dome] Removing an any in usePromise

parent f3b64fdd
No related branches found
No related tags found
No related merge requests found
...@@ -532,8 +532,10 @@ export function usePromise<T>(job: Promise<T>) { ...@@ -532,8 +532,10 @@ export function usePromise<T>(job: Promise<T>) {
const [loading, setLoading] = React.useState(true); const [loading, setLoading] = React.useState(true);
React.useEffect(() => { React.useEffect(() => {
let cancel = false; let cancel = false;
const term = (a: any) => { if (!cancel) { setLoading(false); return a; } }; const doCancel = () => { if (!cancel) setLoading(false); return cancel};
job.then(term(setResult), term(setError)); const onResult = (x: T) => { if (!doCancel()) setResult(x); };
const onError = (e: Error) => {if (!doCancel()) setError(e); };
job.then(onResult, onError);
return () => { cancel = true; }; return () => { cancel = true; };
}, [job]); }, [job]);
return { result, error, loading }; return { result, error, loading };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment