From ff045b24ce9347cad3f8e8d1320073a4669aa9d6 Mon Sep 17 00:00:00 2001 From: Ron Marks Date: Fri, 18 Nov 2022 13:46:21 +0200 Subject: [PATCH] Add resolveFalseAndRemove helper function to modal handler --- src/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index 59cdc9e..7eadcca 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -79,6 +79,12 @@ export interface NiceModalHandler> extends NiceM * Resolve the promise returned by {@link NiceModalHandler.hide | hide} method. */ resolveHide: (args?: unknown) => void; + + /** + * Resolves the promise returned by {@link NiceModalHandler.show | show} method with value `false`, + * then removes the modal using the {@link NiceModalHandler.remove | remove} method. + */ + resolveFalseAndRemove: () => void; } // Omit will not work if extends Record, which is not needed here @@ -339,6 +345,11 @@ export function useModal(modal?: any, args?: any): any { }, [mid], ); + const resolveFalseAndRemove = useCallback(() => { + const modalResolve = modalCallbacks[mid].resolve; + modalResolve(false); + remove(mid); + }, [mid]); return { id: mid, @@ -351,6 +362,7 @@ export function useModal(modal?: any, args?: any): any { resolve: resolveCallback, reject: rejectCallback, resolveHide, + resolveFalseAndRemove, }; } export const create =

(Comp: React.ComponentType

): React.FC

=> {