Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Ambriz
Courses Plus Student 3,902 PointsOther ways to make fetch modular and easier to maintain?
He says in the video you can find more info in the teacher's notes, but I don't see anything. Anyone have a link I can use to view better ways to use fetch aside from the fetchData function in the tutorial?
1 Answer
Daoud Merchant
5,135 PointsPerhaps this doesn't answer your question, but you may like this pattern:
async function doSomething {
const data = await (await fetch(url)).json();
// deal with data
};
The outer call (await (expression).json()
) waits for the inner call (await fetch(url)
) to resolve before firing, and may save you having to write a fetch function requiring maintenance in the first place. This pattern can be found in this FreeCodeCamp tutorial (rest of the tutorial irrelevant for this particular issue).
James Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 PointsJames Crosslin
Full Stack JavaScript Techdegree Graduate 16,882 PointsI came here to ask this same exact question. I'd really love to see these links about how to keep my fetches modular and easier to maintain.