Getting started
Install
sh npm install @dialog-fn/react sh pnpm add @dialog-fn/react sh yarn add @dialog-fn/react Using Svelte? Install @dialog-fn/svelte instead — see the Svelte guide.
The mental model
-
Wrap your component.
createDialog(MyDialog)returns aDialogto render and ashowfunction to open it. -
Render
<Dialog />once. Anywhere in your tree — no provider, no special placement. -
await show(data). It resolves with the value you pass toonConfirm, orundefinedif the user dismisses.
Your first dialog
import { createDialog, type DialogComponentProps } from "@dialog-fn/react";
// Your component receives the injected props — style it however you like.function MyDialog({ isOpen, data, onClose, onConfirm }: DialogComponentProps<{ name: string }, boolean>) { return ( <dialog open={isOpen}> <p>Delete {data?.name}?</p> <button onClick={onClose}>Cancel</button> <button onClick={() => onConfirm?.(true)}>Delete</button> </dialog> );}
// Call once at module scope — types are inferred from MyDialog.const { Dialog, show } = createDialog(MyDialog);
export function Page() { async function remove() { const confirmed = await show({ name: "report.pdf" }); if (confirmed) console.log("deleted"); }
return ( <> <button onClick={remove}>Delete</button> <Dialog /> </> );}That’s the whole API. Next: the core concepts, or copy-paste a recipe with a live, editable playground.