Skip to content

Instantly share code, notes, and snippets.

@tkskumar
Created December 2, 2020 06:29
Show Gist options
  • Save tkskumar/ea02bd9cddba33e120657b95a35c0ba6 to your computer and use it in GitHub Desktop.
Save tkskumar/ea02bd9cddba33e120657b95a35c0ba6 to your computer and use it in GitHub Desktop.
```
setState()
- is Asynchronous
- can have a function as a parameter instead of object
- can accepts a Callback function as a second argument (optional)
- does not return promise
```
function updateState(){
this.setState({load: true}, () => {
console.log(this.state);
})
}
function getData(state){
return new Promise((resolve, reject) => {
this.setState(state, resolve);
})
}
async function updateState(){
await this.setStateAsync({ load: true });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment