diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/constants.ts | 4 | ||||
-rw-r--r-- | src/utils/misc.tsx | 14 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/utils/constants.ts b/src/utils/constants.ts index b0237ad..307de87 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -93,6 +93,10 @@ export const Devs = Object.freeze({ name: "Nickyux", id: 427146305651998721n }, + mantikafasi: { + name: "mantikafasi", + id: 287555395151593473n + }, Xinto: { name: "Xinto", id: 423915768191647755n 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)]; } /** |