1constructor() {
2 // ...
3 this.state = { returnData: null }
4}
5async componentDidMount() {
6 const returnData = await this.Post(...); // Using await to get the result of async func
7 this.setState({ returnData });
8}
9
10async Post(body) {
11 try{
12 const options = {
13 method: 'POST',
14 uri: 'XXXXXXXXXXXXXXXXXXXX',
15 body: body
16 }
17 return rp(options); // define await then return is unnecessary
18 }catch(e){console.warn(e)}
19}
20
21render() {
22 const { returnData } = this.state;
23 // ... Do the rest
24
25}