Created
February 12, 2018 09:11
-
-
Save ivosh/fa8c11f32c7272e156166f9f9f47d139 to your computer and use it in GitHub Desktop.
evolving-react-patterns-async-await
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
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
I couldn't get your gist working but this seems to work :
async componentDidMount() {
this.setState({ content: this.props.loading() })
}