ant-design
  1. ant-design-popconfirm

Ant Design Popconfirm

The Ant Design Popconfirm is a confirmation dialog box that appears when triggered by user action such as a button click, giving the user the choice to confirm or cancel an action. This component is designed to provide a simple and customizable way to get confirmation from users before acting on important events or data changes.

Syntax

import { Popconfirm } from 'antd';

<Popconfirm
  title="Are you sure to delete this item?"
  onConfirm={confirm}
  onCancel={cancel}
  okText="Yes"
  cancelText="No"
>
  <a href="#">Delete</a>
</Popconfirm>

Props

Name Type Default Description
title string/ReactNode - The message to be displayed in the confirmation dialog box.
onConfirm function - The callback function to be called when the user clicks the confirm button.
onCancel function - The callback function to be called when the user clicks the cancel button or clicks outside the dialog box.
okText string/ReactNode Ok The text to be displayed in the confirm button.
cancelText string/ReactNode Cancel The text to be displayed in the cancel button.

Use

The Ant Design Popconfirm can be useful in situations where a user needs to confirm an action before proceeding. For example, it could be used to confirm the deletion of a user's account or to confirm the cancellation of a subscription.

Importance

Confirming user actions is an important part of creating a positive user experience. When a user is asked to confirm an action, they are given a chance to double-check that they are making the correct decision. This can help prevent errors and unnecessary frustration.

Example

import { Popconfirm, message } from 'antd';

function confirm() {
  message.success('User has been deleted.');
}

function cancel() {
  message.error('User deletion was cancelled.');
}

<Popconfirm
  title="Are you sure you want to delete this user?"
  onConfirm={confirm}
  onCancel={cancel}
  okText="Yes"
  cancelText="No"
>
  <Button danger>Delete User</Button>
</Popconfirm>

Summary

The Ant Design Popconfirm is a useful component for confirming user actions. It allows users to confirm or cancel an action before it is carried out, providing a simple and customizable way to obtain confirmation from users. This component can be used in a variety of situations to create a positive user experience and reduce errors.

Published on: