Nextjs Fundamentals · Data Fetching

Parallel data fetching

Promise.all fetching

Parallel data fetching

When a component awaits one request and only then starts the next, the requests run sequentially — a request waterfall. The second request cannot begin until the first has finished, so the total time is the sum of every round-trip:

const artist = await getArtist(username);
const albums = await getAlbums(username); // starts only after the first

The fix is to start every request first, then await them together with Promise.all. Calling an async function returns a promise immediately, so the requests are already in flight before you wait:

const artistData = getArtist(username);
const albumsData = getAlbums(username);

const [artist, albums] = await Promise.all([artistData, albumsData]);

Now both requests run in parallel and the component waits for the slowest one, not the sum. In the App Router this pattern is how a page avoids a waterfall inside a single component.

In this Challenge the preview runs in the browser, so the fetches happen in an effect after render rather than during an async render. The pattern is the same: kick off both fetches, then await Promise.all to collect their results.

You will now practise this pattern: fetch two Pokémon in parallel and render both names.

Challenge

Export an App component from App.jsx that fetches two Pokémon in parallel. Start both fetch calls before awaiting anything, then collect their names with Promise.all and render each name as a list item. The fetches belong in a useEffect, since the preview runs in the browser.

The Test stubs fetch, renders App, and expects both names to appear, so the starter — which renders an empty list — fails.

Pokémon and Pokémon character names are trademarks of Nintendo.

App.jsx
export function App() {
  return <ul />;
}

No test run yet

The Test is hidden. Run it to check the Challenge — you only see the result, never the test source.