Parallel data fetching helps get multiple pieces of data at the same time. This makes your app faster because it does not wait for one request to finish before starting the next.
When your page needs data from several APIs or sources at once.
When you want to load user info and product details together.
When you want to show multiple lists or sections that come from different places.
When you want to reduce waiting time for users by fetching data simultaneously.
This Next.js page fetches user info and their posts at the same time using Promise.all. It then shows the user's name and email, followed by a list of their post titles.
Each fetch returns a Response object with a status property indicating HTTP status.
Step 2: Analyze Promise.all result
Promise.all waits for both fetches and returns an array of Response objects. Logging userRes.status and postsRes.status prints their HTTP status codes.
Final Answer:
200 200 -> Option A
Quick Check:
Response.status = 200 if successful [OK]
Hint: fetch returns Response objects with status property [OK]
Common Mistakes:
Expecting fetch to return JSON directly
Logging promises instead of awaited results
Confusing undefined with Response properties
4. What is wrong with this Next.js code that tries to fetch two APIs in parallel?
A. Nothing is wrong; this code fetches data correctly.
B. The fetch calls are not awaited in parallel, causing sequential fetching.
C. The function should use Promise.all to fetch in parallel.
D. You cannot call json() on a promise; you must await the fetch first.
Solution
Step 1: Identify the type of res1 and res2
Both res1 and res2 are promises from fetch, not Response objects yet.
Step 2: Understand json() usage
You must await the fetch promise to get the Response object before calling json(). Calling json() directly on a promise causes an error.
Final Answer:
You cannot call json() on a promise; you must await the fetch first. -> Option D
Quick Check:
Await fetch before json() [OK]
Hint: Always await fetch before calling json() [OK]
Common Mistakes:
Calling json() on a fetch promise without awaiting
Assuming fetch returns JSON directly
Not using Promise.all for parallelism
5. You want to fetch user info and user posts in parallel in Next.js, but only display posts if user info fetch succeeds. Which approach correctly handles this?
hard
A. Use Promise.all for both fetches and check user info response before rendering posts.
B. Fetch user info first, then fetch posts only if user info fetch succeeds.
C. Use Promise.allSettled to fetch both, then conditionally render posts if user info succeeded.
D. Fetch posts first, then fetch user info regardless of posts fetch result.
Solution
Step 1: Understand requirement for conditional rendering
Posts should display only if user info fetch succeeds, so we need to know each fetch's success independently.
Step 2: Choose correct parallel fetching method
Promise.all fails fast if any promise rejects, so it can't handle partial success. Promise.allSettled waits for all promises and reports each result, allowing conditional logic.
Step 3: Apply conditional rendering logic
After Promise.allSettled, check user info status; if successful, render posts, else skip posts.
Final Answer:
Use Promise.allSettled to fetch both, then conditionally render posts if user info succeeded. -> Option C
Quick Check:
Conditional render needs allSettled [OK]
Hint: Use allSettled to handle partial success in parallel fetches [OK]
Common Mistakes:
Using Promise.all which fails on first error
Fetching posts before confirming user info success
Not handling fetch failures gracefully
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.