For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/confirm.md.
Ask for confirmation before an important action and await the user's choice.
Use Modal for editing, or Popconfirm for a brief confirmation beside a trigger.
Set up ConfigProvider at the application entry, then call useConfirm() in a child component. Each confirmation inherits the caller's theme and language.
import { ConfigProvider } from '@ifhover/leaf-ui';export function Root() { return ( <ConfigProvider> <App /> </ConfigProvider> );}
Use type to select a semantic state; it defaults to info. type="default" omits the built-in icon, and icon={null} hides the icon for any type. success hides Cancel by default; set showCancel to display it.
status.tsx
import { Button, Space, useConfirm } from '@ifhover/leaf-ui';export function ConfirmStatus() { const { confirm } = useConfirm(); return ( <Space wrap> <Button onClick={() => confirm({ type: 'info', title: 'Share this link?', children: 'Anyone with the link can view this page.', }) } > Information </Button> <Button onClick={() => confirm({ type: 'success', title: 'Export ready', children: 'Your file is ready to download.', }) } > Success </Button> <Button onClick={() => confirm({ type: 'warning', title: 'Leave this page?', children: 'Unsaved changes will be lost.', }) } > Warning </Button> </Space> );}
Place the async action in onConfirm. Success closes the dialog automatically and resolves to true. While pending, the default buttons show loading and prevent repeated confirmation or cancellation.
A rejected onConfirm displays the error and keeps the dialog open for another attempt. Each new confirmation in this example fails once, then succeeds on the second attempt.
retry.tsx
import { Button, Space, Text, useConfirm } from '@ifhover/leaf-ui';import { useState } from 'react';export function ConfirmRetry() { const { confirm } = useConfirm(); const [result, setResult] = useState(''); return ( <Space direction="vertical" align="start"> <Button onClick={async () => { let attempts = 0; setResult(''); const accepted = await confirm({ type: 'warning', title: 'Submit changes?', children: 'The first attempt simulates a failure. Confirm again to retry.', onConfirm: async () => { await new Promise<void>((resolve) => setTimeout(resolve, 600)); if (++attempts === 1) throw new Error('Unable to submit. Please try again.'); }, }); setResult(accepted ? 'Changes submitted' : 'Submission cancelled'); }} > Submit with retry </Button> {result && ( <Text tone="muted" role="status"> {result} </Text> )} </Space> );}
The returned object is ConfirmApi. Requests in the same queue appear in sequence, after the previous dialog finishes closing. The Promise resolves when the decision closes the dialog, without waiting for its closing animation.
Unmounting the caller or provider resolves outstanding requests to false. It does not abort an async action already in progress or invoke onCancel.
Resolve to a boolean on decision: true after successful confirmation, false on cancellation or caller unmount, without waiting for the closing animation.
Without ConfigProvider, wrap the application in ConfirmProvider. An explicit ConfirmProvider creates an independent queue; a nested ConfigProvider continues to share the existing queue.
import { ConfirmProvider } from '@ifhover/leaf-ui';export function Root() { return ( <ConfirmProvider> <App /> </ConfirmProvider> );}
Property
Type
Default
Description
children
ReactNode
—
Contents sharing this independent confirmation queue; ConfigProvider already supplies a queue and nested ConfigProviders reuse it.