DEV Community

loading...

Discussion on: Caching API requests in JavaScript

Collapse
leoawesome profile image
Leo

Bro.
Is await with then 2 times the best practices??

Collapse
Sloan, the sloth mascot
Comment deleted
Collapse
luigicampbell profile image
luigicampbell

I think Leo means you can await the json call within the async function.

I think something like:

const res = await fetch(url);
const weatherInfo = await res.json();

return weatherInfo;
Thread Thread
adancarrasco profile image
Adán Carrasco Author

Thanks for the example luigicampbell!

Collapse
adancarrasco profile image
Adán Carrasco Author

Thanks for the feedback Leo! To be honest I haven't check the best practices for fetch. Do you have a link where I can take a look? :)