Skip to content

Instantly share code, notes, and snippets.

@barbagrigia
Forked from ivosh/index.js
Created February 12, 2018 18:21
Show Gist options
  • Save barbagrigia/e3dadaaa84ad6a3ef63e230115049a6d to your computer and use it in GitHub Desktop.
Save barbagrigia/e3dadaaa84ad6a3ef63e230115049a6d to your computer and use it in GitHub Desktop.
evolving-react-patterns-async-await
componentDidMount() {
this.setState({ content: this.props.loading() })
try {
const res = await fetch(this.props.url);
this.setState({ content: this.props.done(res.json()) });
} catch (err) {
this.setState({ content: this.props.error() });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment