aboutsummaryrefslogtreecommitdiff
path: root/src/utils/misc.tsx
diff options
context:
space:
mode:
authorTymanWasTaken <tbeckman530@gmail.com>2022-10-17 10:05:22 -0600
committerGitHub <noreply@github.com>2022-10-17 18:05:22 +0200
commitae730e83984cbf4dc804eebbf260a055bfe635c0 (patch)
tree85625f1b4108525f85a61b2ac530e0ae0d234796 /src/utils/misc.tsx
parentad054d5c656967e00191027d729d3570128bb557 (diff)
downloadVencord-ae730e83984cbf4dc804eebbf260a055bfe635c0.tar.gz
Vencord-ae730e83984cbf4dc804eebbf260a055bfe635c0.tar.bz2
Vencord-ae730e83984cbf4dc804eebbf260a055bfe635c0.zip
Add pronoundb plugin (#104)
Diffstat (limited to 'src/utils/misc.tsx')
-rw-r--r--src/utils/misc.tsx7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx
index f6ea36c..66ea202 100644
--- a/src/utils/misc.tsx
+++ b/src/utils/misc.tsx
@@ -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);
}, []);