Skip to content

Instantly share code, notes, and snippets.

@MarkNewcomb1
Last active December 7, 2018 16:37
Show Gist options
  • Select an option

  • Save MarkNewcomb1/450d67de1009b757ddf6c593f48cb4f3 to your computer and use it in GitHub Desktop.

Select an option

Save MarkNewcomb1/450d67de1009b757ddf6c593f48cb4f3 to your computer and use it in GitHub Desktop.
Async with react
const apiUrl = './dinosaurs.json'
// constructor stuff
componentDidMount() {
this.fetchProfiles()
}
async fetchProfiles() {
const response = await fetch(apiUrl)
const json = await response.json()
console.log(json)
this.setState({
profiles: json
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment