aboutsummaryrefslogtreecommitdiff
path: root/src/utils/misc.tsx
diff options
context:
space:
mode:
authorManti <67705577+mantikafasi@users.noreply.github.com>2022-11-16 02:40:46 +0300
committerGitHub <noreply@github.com>2022-11-16 00:40:46 +0100
commit84ec839b041a0da2a7a950c47f003d5bebfe4685 (patch)
tree54ec06d2ecc13ccbc3908194f60b277d24f9d70f /src/utils/misc.tsx
parentb30508aef8cd19625640ee650b58b557bb3fdd24 (diff)
downloadVencord-84ec839b041a0da2a7a950c47f003d5bebfe4685.tar.gz
Vencord-84ec839b041a0da2a7a950c47f003d5bebfe4685.tar.bz2
Vencord-84ec839b041a0da2a7a950c47f003d5bebfe4685.zip
Add ReviewDB Plugin (#187)
Co-authored-by: Ven <vendicated@riseup.net>
Diffstat (limited to 'src/utils/misc.tsx')
-rw-r--r--src/utils/misc.tsx14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx
index 55e0c22..005bcc0 100644
--- a/src/utils/misc.tsx
+++ b/src/utils/misc.tsx
@@ -40,21 +40,23 @@ export function lazyWebpack<T = any>(filter: FilterFn): T {
return proxyLazy(() => find(filter));
}
+type AwaiterRes<T> = [T, any, boolean, () => void];
/**
* Await a promise
* @param factory Factory
* @param fallbackValue The fallback value that will be used until the promise resolved
* @returns [value, error, isPending]
*/
-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: 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] {
+export function useAwaiter<T>(factory: () => Promise<T>): AwaiterRes<T | null>;
+export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T): AwaiterRes<T>;
+export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: null, onError: (e: unknown) => unknown): AwaiterRes<T>;
+export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null = null, onError?: (e: unknown) => unknown): AwaiterRes<T | null> {
const [state, setState] = React.useState({
value: fallbackValue,
error: null,
pending: true
});
+ const [signal, setSignal] = React.useState(0);
React.useEffect(() => {
let isAlive = true;
@@ -63,9 +65,9 @@ export function useAwaiter<T>(factory: () => Promise<T>, fallbackValue: T | null
.catch(error => isAlive && (setState({ value: null, error, pending: false }), onError?.(error)));
return () => void (isAlive = false);
- }, []);
+ }, [signal]);
- return [state.value, state.error, state.pending];
+ return [state.value, state.error, state.pending, () => setSignal(signal + 1)];
}
/**