Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ export interface NiceModalHandler<Props = Record<string, unknown>> 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<string, unknown>, which is not needed here
Expand Down Expand Up @@ -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,
Expand All @@ -351,6 +362,7 @@ export function useModal(modal?: any, args?: any): any {
resolve: resolveCallback,
reject: rejectCallback,
resolveHide,
resolveFalseAndRemove,
};
}
export const create = <P extends {}>(Comp: React.ComponentType<P>): React.FC<P & NiceModalHocProps> => {
Expand Down