react promise function code example
Example: react promises
componentWillMount() {
var promise = new Promise( (resolve, reject) => {
let name = 'Paul'
if (name === 'Paul') {
resolve("Promise resolved successfully");
}
else {
reject(Error("Promise rejected"));
}
});
let obj = {newName: ''};
promise.then( result => {
this.setState({name: result});
}, function(error) {
this.setState({name: error});
});
}