Skip to content

useConfirmation

Manages confirmation dialog state with promise-based flow.

Signature

ts
function useConfirmation(): UseConfirmationReturn

Return Type

UseConfirmationReturn

PropertyTypeDescription
stateConfirmationStateCurrent dialog state
confirm(options: ConfirmOptions) => Promise<boolean>Request confirmation
handleConfirm() => voidHandle user confirming
handleCancel() => voidHandle user canceling

ConfirmationState

PropertyTypeDescription
isOpenbooleanWhether dialog is open
optionsConfirmOptions | nullCurrent dialog options

ConfirmOptions

PropertyTypeDefaultDescription
titlestringRequiredDialog title
descriptionstring-Dialog description
confirmLabelstring'Confirm'Confirm button text
cancelLabelstring'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}
/>

See also