React
npm install @dialog-fn/reactcreateDialog(Component, options?)
Pass your dialog component; get back an instance:
const { Dialog, show, close } = createDialog(MyDialog, { /* forceUnmount, delayUnmount */});Dialog— render once, anywhere. Optionalstateprop forwards extra render-time state:<Dialog state={theme} />.show(data)— opens the dialog; returnsPromise<K | undefined>(confirm value, orundefinedwhen dismissed). A plain function — usable in handlers, services, or outside React entirely.show.close()/close()— dismiss programmatically.
Call createDialog() once at module scope — the store is a singleton shared by every
render of Dialog.
Typed generics
Types are inferred from your component’s props, or set them explicitly:
// inferred from MyDialog: DialogComponentProps<In, Out>const { show } = createDialog(MyDialog);
// or explicitconst { show } = createDialog<In, Out>(MyDialog);Your component
import type { DialogComponentProps } from "@dialog-fn/react";
function MyDialog({ isOpen, data, onClose, onConfirm }: DialogComponentProps<In, Out>) { return ( <dialog open={isOpen}> {/* call onConfirm(value) to resolve, onClose() to dismiss */} </dialog> );}Accessibility:
<dialog open>is non-modal. For a real modal (focus trap,Esc, backdrop), drive a<dialog>withshowModal()in an effect and forward the nativecancelevent toonClose.
See it live in the recipes or the full API reference.