Composables
useConfirm
Programmatic confirmation dialog that returns a Promise resolving to true on confirm or false on cancel.
useConfirm
Replaces window.confirm with a branded modal. Call confirm(message) anywhere in your async code and await the Promise<boolean> — it resolves true when the user clicks confirm and false when they cancel. The XAConfirmModal component reads the shared state this composable manages.
Usage
const { confirm, isOpen, message, resolve } = useConfirm()
Returns
| Key | Type | Description |
|---|---|---|
confirm | (message: string, options?: ConfirmOptions) => Promise<boolean> | Opens the dialog with the given message; resolves when the user responds. |
isOpen | Ref<boolean> | Whether the confirmation dialog is currently visible. |
message | Ref<string> | The message text currently displayed in the dialog. |
resolve | (value: boolean) => void | Called internally by the modal to settle the pending promise. |
Example
const { confirm } = useConfirm()
const { remove } = useXCrud("/api/users")
const { success } = useXToast()
async function deleteUser(id: string, name: string) {
const ok = await confirm(`Are you sure you want to delete ${name}?`)
if (!ok) return
await remove(id)
success("User deleted")
}
AI Context
composable: useConfirm
package: "@xenterprises/nuxt-x-app"
use-when: >
Any destructive or irreversible action — deleting records, bulk removes,
revoking access — where you need the user to explicitly confirm before
proceeding. Await the promise and bail out early on false.
pairs-with: XAConfirmModal, XABulkAction, useXCrud, useXToast
