We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dear Authors,
The code snippet in Ch 2 returns undefined:
const getFakePerson = async () => { try { let res = await fetch("https://api.randomuser.me/?nat=US&results=1"); let { results } = res.json(); console.log(results); } catch (error) { console.error(error); } }; getFakePerson();
I believe the solution is to add await before the res.json():
await
res.json()
const getFakePerson = async () => { try { let res = await fetch("https://api.randomuser.me/?nat=US&results=1"); let { results } = await res.json(); console.log(results); } catch (error) { console.error(error); } }; getFakePerson();
The text was updated successfully, but these errors were encountered:
Thank you! I attached .then(res => res.json()) to the fetch() and deleted the let { results } = res.json() but your solution looks much much nicer.
.then(res => res.json())
fetch()
let { results } = res.json()
Sorry, something went wrong.
It´s work for me
`const getFakePerson = async () => { try { let res = await fetch("https://api.randomuser.me/?nat=US&results=1"); let results = await res.json(); console.log(results); } catch (error) { console.error(error); } };
getFakePerson();`
As the fetch returns a promise from the first await, then the second await is natural to add for resolving into value.
No branches or pull requests
Dear Authors,
The code snippet in Ch 2 returns undefined:
I believe the solution is to add
await
before theres.json()
:The text was updated successfully, but these errors were encountered: