Skip to content

Instantly share code, notes, and snippets.

@Zvax
Created November 21, 2017 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zvax/041fdaa9355032951359bfb20865e0b3 to your computer and use it in GitHub Desktop.
Save Zvax/041fdaa9355032951359bfb20865e0b3 to your computer and use it in GitHub Desktop.
how to act synchronously in nested function calls
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