Skip to content

Instantly share code, notes, and snippets.

@SalithaUCSC
Last active February 4, 2019 02:20
Sweet Alert integration with React JS
addUser(e) {
e.preventDefault();
const dataTobeSaved = {
name: this.state.name,
age: this.state.age
}
axios.post('api_url', dataTobeSaved)
.then(res => {
swal({
title: "Done!",
text: "user is added to database",
icon: "success",
timer: 2000,
button: false
})
this.setState({ redirect: this.state.redirect === false });
})
.catch(err => {
console.log(err)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment