Skip to content

Instantly share code, notes, and snippets.

@isabellachen
Last active January 4, 2018 16:44
Show Gist options
  • Save isabellachen/39be0aa1478e26c8f70fbd40859cb68a to your computer and use it in GitHub Desktop.
Save isabellachen/39be0aa1478e26c8f70fbd40859cb68a to your computer and use it in GitHub Desktop.
Use Promise All to return an array of values derived from a fetch call to an API
const fetchFromGithub = async (endpoint) => {
const url = `https://api.github.com/users/${endpoint}`
const response = await fetch(url)
return await response.json()
}
const getGithubUserInfo = async (handle) => {
return await Promise.all([
fetchFromGithub(handle),
fetchFromGithub(`${handle}/repos`)
])
}
getGithubUserInfo('isabellachen').then(data => {
console.log(data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment