@cicara/better-modal
Advanced tools
Comparing version 0.0.1-0 to 0.0.1-1
/// <reference types="react" /> | ||
export type ModalContextValue<R = unknown> = { | ||
export type ModalContextValue<R> = { | ||
visible: boolean; | ||
@@ -8,2 +8,2 @@ reject: (reason: unknown) => void; | ||
}; | ||
export declare const ModalContext: import("react").Context<ModalContextValue<unknown> | undefined>; | ||
export declare const ModalContext: import("react").Context<ModalContextValue<any> | undefined>; |
@@ -1,6 +0,6 @@ | ||
import { type ComponentType } from "react"; | ||
import { ComponentType } from "react"; | ||
export type ShowFunc<P, R = unknown> = (props: P) => Promise<R>; | ||
export declare function useModal<P = object>(ModalComponent: ComponentType<P>): { | ||
show: ShowFunc<P, unknown>; | ||
export declare function useModal<P>(ModalComponent: ComponentType<P>): { | ||
show: <R>(props: P) => Promise<R>; | ||
placeholder: import("react/jsx-runtime").JSX.Element | null; | ||
}; |
@@ -9,8 +9,5 @@ import { jsx as _jsx } from "react/jsx-runtime"; | ||
const placeholder = useMemo(() => { | ||
if (!promiseRef.current) { | ||
if (!(modalProps && promiseRef.current)) { | ||
return null; | ||
} | ||
if (!modalProps) { | ||
return null; | ||
} | ||
return (_jsx(ModalContext.Provider, { value: { | ||
@@ -26,3 +23,3 @@ visible, | ||
}, [ModalComponent, modalProps, visible]); | ||
const show = useCallback(async (props) => { | ||
const show = useCallback(async function (props) { | ||
try { | ||
@@ -29,0 +26,0 @@ setModalProps(props); |
{ | ||
"name": "@cicara/better-modal", | ||
"version": "0.0.1-0", | ||
"version": "0.0.1-1", | ||
"description": "a tool to help simplify antd modal state management", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -69,3 +69,3 @@ # Better Modal | ||
export function App() { | ||
const myModal = useModal<string>(MyModal); | ||
const myModal = useModal(MyModal); | ||
@@ -85,7 +85,7 @@ return <div>{myModal.placeholder}</div>; | ||
export function App() { | ||
const myModal = useModal<string>(MyModal); | ||
const myModal = useModal(MyModal); | ||
const handleOpenModal = useCallback(async () => { | ||
try { | ||
const result = await myModal.show({ value: "hungtcs" }); | ||
const result = await myModal.show<string>({ value: "hungtcs" }); | ||
alert(result); | ||
@@ -92,0 +92,0 @@ } catch (err) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7674
73