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>
);
}
}
import React from 'react'
import { withAlert } from 'react-alert'
const App = ({ alert }) => (
<button
onClick={() => {
alert.show('Oh look, an alert!')
}}
>
Show Alert
</button>
)
export default withAlert()(App)