Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Forked from tkskumar/setstate
Created December 2, 2020 06:29
Show Gist options
  • Save tkssharma/5e7fa330e1f3bd98bf8206ecbf3bf9d4 to your computer and use it in GitHub Desktop.
Save tkssharma/5e7fa330e1f3bd98bf8206ecbf3bf9d4 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