async await react stackoverflow
constructor() {
// ...
this.state = { returnData: null }
}
async componentDidMount() {
const returnData = await this.Post(...); // Using await to get the result of async func
this.setState({ returnData });
}
async Post(body) {
try{
const options = {
method: 'POST',
uri: 'XXXXXXXXXXXXXXXXXXXX',
body: body
}
return rp(options); // define await then return is unnecessary
}catch(e){console.warn(e)}
}
render() {
const { returnData } = this.state;
// ... Do the rest
}
Also in JavaScript:
- angular viewchild input element value
- get every other item in an array
- how to define state in react function
- add class to html tag javascript
- javascript números pegar apenas o decimal
- javascript remove element
- how get count of letters in javascript
- js page reload
- how to numeric value is after point 2 values in javascript
- stopped typing jquery
- total array with function
- validador de cep javascript
- js remove item array
- pass php variable to javascript
- store data in localstorage chrome as per address bar url using javascript
- javascript backslash
- "rbac" react redux navigation bar
- does json only support ascii
- ejs include dynamic partial
- react native keyboard event listener
- redux devtools with middleware
- ajouter un lien href dans du javascript
- open html file in browser using package.json
- angular viewchild set attribute