Created
December 2, 2020 06:29
-
-
Save tkskumar/ea02bd9cddba33e120657b95a35c0ba6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
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