react-confirm-alert
TypeScript icon, indicating that this package has built-in type declarations

3.0.6 • Public • Published

react-confirm-alert

React 18 is supported!!

For React <= 17.x.x use version 2.x.x

React component confirm dialog. Live demo

npm version

Document for v.1.x.x, v.2.x.x

Getting started

Install with NPM:

$ npm install react-confirm-alert --save

Options

const options = {
  title: 'Title',
  message: 'Message',
  buttons: [
    {
      label: 'Yes',
      onClick: () => alert('Click Yes')
    },
    {
      label: 'No',
      onClick: () => alert('Click No')
    }
  ],
  closeOnEscape: true,
  closeOnClickOutside: true,
  keyCodeForClose: [8, 32],
  willUnmount: () => {},
  afterClose: () => {},
  onClickOutside: () => {},
  onKeypress: () => {},
  onKeypressEscape: () => {},
  overlayClassName: "overlay-custom-class-name"
};

confirmAlert(options);

Use with function:

import { confirmAlert } from 'react-confirm-alert'; // Import
import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css

class App extends React.Component {
  submit = () => {
    confirmAlert({
      title: 'Confirm to submit',
      message: 'Are you sure to do this.',
      buttons: [
        {
          label: 'Yes',
          onClick: () => alert('Click Yes')
        },
        {
          label: 'No',
          onClick: () => alert('Click No')
        }
      ]
    });
  };

  render() {
    return (
      <div className='container'>
        <button onClick={this.submit}>Confirm dialog</button>
      </div>
    );
  }
}

Custom UI Component

confirmAlert({
  customUI: ({ onClose }) => {
    return (
      <div className='custom-ui'>
        <h1>Are you sure?</h1>
        <p>You want to delete this file?</p>
        <button onClick={onClose}>No</button>
        <button
          onClick={() => {
            this.handleClickDelete();
            onClose();
          }}
        >
          Yes, Delete it!
        </button>
      </div>
    );
  }
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.620,148latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.620,148
3.0.54
3.0.42
3.0.31
3.0.227
3.0.14
3.0.02
2.8.015,546
2.7.03,646
2.6.2494
2.6.11,043
2.6.014
2.5.16
2.5.00
2.4.1341
2.4.039
2.3.06
2.2.09
2.1.024
2.0.7129
2.0.619
2.0.547
2.0.42
2.0.30
2.0.2104
2.0.10
2.0.021
1.0.8211
1.0.731
1.0.61
1.0.50
1.0.40
1.0.31
1.0.21
1.0.13
1.0.02

Package Sidebar

Install

npm i react-confirm-alert

Weekly Downloads

41,928

Version

3.0.6

License

MIT

Unpacked Size

19.1 kB

Total Files

9

Last publish

Collaborators

  • ga-mo