1componentWillMount() {
2 var promise = new Promise( (resolve, reject) => {
3
4 let name = 'Paul'
5
6 if (name === 'Paul') {
7 resolve("Promise resolved successfully");
8 }
9 else {
10 reject(Error("Promise rejected"));
11 }
12 });
13
14 let obj = {newName: ''};
15
16 promise.then( result => {
17 this.setState({name: result});
18 }, function(error) {
19 this.setState({name: error});
20 });
21}
1componentWillMount() {
2 var promise = new Promise( (resolve, reject) => {
3
4 let name = 'Paul'
5
6 if (name === 'Paul') {
7 resolve("Promise resolved successfully");
8 }
9 else {
10 reject(Error("Promise rejected"));
11 }
12 });
13
14 let obj = {newName: ''};
15
16 promise.then( result => {
17 this.setState({name: result});
18 }, function(error) {
19 this.setState({name: error});
20 });
21}
22