Skip to content

Core concepts

dialog-fn does exactly one thing: it controls a dialog’s visibility and turns the confirm/dismiss interaction into a single promise. Rendering, styling, and accessibility are yours.

The promise model

show(data) returns a promise that always resolves, never rejects:

  • Confirm → resolves with the value you pass to onConfirm(value).
  • Dismiss (close, supersede, or unmount) → resolves with undefined.
const result = await show(data);
if (result) {
// confirmed — `result` is your onConfirm value
} else {
// dismissed
}

Because it never rejects, you don’t need try/catch. If you call show() again while a dialog is open, the previous promise resolves as dismissed (it never hangs).

Injected props

Your component receives these (all optional, typed via DialogComponentProps<T, K, S>):

PropTypeDescription
isOpenbooleanWhether the dialog is open.
dataTThe argument passed to show(data).
onConfirm(value?: K) => voidCall to resolve the promise with a value.
onClose() => voidCall to dismiss (resolves undefined).
stateSOptional extra render-time state (see below).

Mount options

createDialog(Component, options?) accepts:

OptionTypeDefaultDescription
forceUnmountbooleanfalseUnmount the component when closed (instead of just toggling open).
delayUnmountnumber0Ms to wait before unmounting — lets an exit transition finish.

Leave both off and your component stays mounted, toggling on isOpen (great for CSS transitions). Turn them on for true unmount + exit animations — see the Animated recipe.