Add pronoundb plugin (#104)

This commit is contained in:
TymanWasTaken 2022-10-17 10:05:22 -06:00 committed by GitHub
parent ad054d5c65
commit ae730e8398
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 143 additions and 4 deletions

View file

@ -30,10 +30,11 @@ export function lazyWebpack<T = any>(filter: FilterFn): T {
*/
export function useAwaiter<T>(factory: () => Promise<T>): [T | null, any, boolean];
export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T): [T, any, boolean];
export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null = null): [T | null, any, boolean] {
export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: null, onError: (e: unknown) => unknown): [T, any, boolean];
export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null = null, onError?: (e: unknown) => unknown): [T | null, any, boolean] {
const [state, setState] = React.useState({
value: fallbackValue,
error: null as any,
error: null,
pending: true
});
@ -41,7 +42,7 @@ export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null
let isAlive = true;
factory()
.then(value => isAlive && setState({ value, error: null, pending: false }))
.catch(error => isAlive && setState({ value: null, error, pending: false }));
.catch(error => isAlive && (setState({ value: null, error, pending: false }), onError?.(error)));
return () => void (isAlive = false);
}, []);