feat: implement long-lived sessions

This commit is contained in:
Julian Tölle 2020-09-05 23:35:53 +02:00
parent d0705afca8
commit 44f7e26270
35 changed files with 739 additions and 190 deletions

View file

@ -3,7 +3,12 @@ import { useCallback, useEffect, useState } from "react";
type UseAsync = <T>(
asyncFunction: () => Promise<T>,
initialValue: T
) => { pending: boolean; value: T; error: Error | null };
) => {
pending: boolean;
value: T;
error: Error | null;
reload: () => Promise<void>;
};
export const useAsync: UseAsync = <T extends any>(
asyncFunction: () => Promise<T>,
@ -34,5 +39,5 @@ export const useAsync: UseAsync = <T extends any>(
execute();
}, [execute]);
return { execute, pending, value, error };
return { reload: execute, pending, value, error };
};