Appearance
useConfirmation
Manages confirmation dialog state with promise-based flow.
Signature
ts
function useConfirmation(): UseConfirmationReturnReturn Type
UseConfirmationReturn
| Property | Type | Description |
|---|---|---|
state | ConfirmationState | Current dialog state |
confirm | (options: ConfirmOptions) => Promise<boolean> | Request confirmation |
handleConfirm | () => void | Handle user confirming |
handleCancel | () => void | Handle user canceling |
ConfirmationState
| Property | Type | Description |
|---|---|---|
isOpen | boolean | Whether dialog is open |
options | ConfirmOptions | null | Current dialog options |
ConfirmOptions
| Property | Type | Default | Description |
|---|---|---|---|
title | string | Required | Dialog title |
description | string | - | Dialog description |
confirmLabel | string | 'Confirm' | Confirm button text |
cancelLabel | string | 'Cancel' | Cancel button text |
variant | 'default' | 'destructive' | 'default' | Visual variant |
Example
tsx
const { state, confirm, handleConfirm, handleCancel } = useConfirmation()
const handleDelete = async () => {
const confirmed = await confirm({
title: 'Delete item?',
description: 'This cannot be undone.',
variant: 'destructive',
})
if (confirmed) await deleteItem()
}
<ConfirmDialog
open={state.isOpen}
options={state.options}
onConfirm={handleConfirm}
onCancel={handleCancel}
/>