From 3e3d05fc26a634b17549c9473bd8aeebb7dec4ec Mon Sep 17 00:00:00 2001 From: Manti <67705577+mantikafasi@users.noreply.github.com> Date: Sun, 28 May 2023 23:03:06 +0300 Subject: ReviewDB: Add Review Modal & Pagination (#1174) Co-authored-by: V --- src/utils/react.tsx | 13 +++++++++++-- src/utils/types.ts | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/react.tsx b/src/utils/react.tsx index 69c1df2..a4c7152 100644 --- a/src/utils/react.tsx +++ b/src/utils/react.tsx @@ -67,6 +67,7 @@ interface AwaiterOpts { fallbackValue: T; deps?: unknown[]; onError?(e: any): void; + onSuccess?(value: T): void; } /** * Await a promise @@ -94,8 +95,16 @@ export function useAwaiter(factory: () => Promise, providedOpts?: AwaiterO if (!state.pending) setState({ ...state, pending: true }); factory() - .then(value => isAlive && setState({ value, error: null, pending: false })) - .catch(error => isAlive && (setState({ value: null, error, pending: false }), opts.onError?.(error))); + .then(value => { + if (!isAlive) return; + setState({ value, error: null, pending: false }); + opts.onSuccess?.(value); + }) + .catch(error => { + if (!isAlive) return; + setState({ value: null, error, pending: false }); + opts.onError?.(error); + }); return () => void (isAlive = false); }, opts.deps); diff --git a/src/utils/types.ts b/src/utils/types.ts index 5c7a85c..c81b13a 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -277,6 +277,8 @@ export interface DefinedSettings(): this & { store: T; }; } export type PartialExcept = Partial & Required>; -- cgit