Last active
February 4, 2019 02:20
Sweet Alert integration with React JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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