-
-
Save Zvax/041fdaa9355032951359bfb20865e0b3 to your computer and use it in GitHub Desktop.
how to act synchronously in nested function calls
This file contains 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
tryCredentials = () => { | |
const encodedCredentials = encodeCredentials(this.state.username, this.state.password); | |
// setEncodedCredentials is a func passed in props | |
// I would like to wait on it without implementing promises everywhere | |
this.props.setEncodedCredentials(encodedCredentials); | |
// fetchProjects should be fired only after 'finished setting credentials' gets logged | |
this.props.fetchProjects(); | |
}; | |
setEncodedCredentials = encodedCredentials => { | |
console.log('setting encoded credentials'); | |
this.setState({ | |
...this.state, | |
encodedCredentials: encodedCredentials | |
}, () => console.log('finished setting credentials')); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment