I am using react-js in my project.
const SweetAlert = require('react-sweetalert2');
const Updater = React.createClass({
<div style={{ padding: "20px" }}>
<a onClick={() => this.deleteThisGoal()} className="btn btn-danger"> <i className="fa fa-trash" aria-hidden="true" />
Delete Goal
</a>
{this.state.alert}
</div>
deleteThisGoal: function() {
const getAlert = (
<SweetAlert success title="Woot!">
Hello world!
</SweetAlert>
);
this.setState({
alert: getAlert
});
}
});
When I inspect the element the value gets assigned to this.state.alert
but when I click on the alert no popup shows up.
Can anyone point me in the right direction?
I referred Add Sweet Alert popup to button in React component for the example.
Updated my answer with:
const SweetAlert = require('react-sweetalert2');
const Updater = React.createClass({
render(
<div>
<div style={{ padding: '20px' }}> <a onClick={this.deleteThisGoal} className='btn btn-danger' > Delete Goal </a>
</div>
{this.popup}
</div>
);
},
deleteThisGoal: function() {
this.setState({
show: true
});
},
popup: function(keyword) {
return (
<SweetAlert
show={this.state.show} title="Deleted goal" text="Goal was deleted!"
onConfirm={() => this.setState({ show: false })}>
</SweetAlert>
);
}
});
still no alert that I can see.