Challenge - 5 Problems
Server Data Fetching Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this server component fetching data?
Consider this Next.js server component fetching user data. What will it render?
NextJS
import React from 'react'; async function getUser() { return { name: 'Alice', age: 30 }; } export default async function User() { const user = await getUser(); return <div>{`Name: ${user.name}, Age: ${user.age}`}</div>; }
Attempts:
2 left
💡 Hint
Server components can use async/await directly for data fetching.
✗ Incorrect
Server components in Next.js can fetch data using async functions and await. The getUser function returns an object with name and age, which is rendered correctly.
📝 Syntax
intermediate2:00remaining
Which option correctly fetches data in a Next.js server component?
Identify the correct way to fetch data inside a Next.js server component.
Attempts:
2 left
💡 Hint
Server components support async/await and fetch API directly.
✗ Incorrect
Option D correctly uses async function, awaits fetch and json parsing before rendering. Option D does not await fetch, so data is a Promise. Option D uses useEffect which is client-only. Option D calls .json() on Promise without await causing error.
🔧 Debug
advanced2:00remaining
Why does this server component cause a runtime error?
Examine this Next.js server component code. Why does it throw an error at runtime?
NextJS
export default function Page() { const data = await fetch('https://api.example.com/data').then(res => res.json()); return <div>{data.name}</div>; }
Attempts:
2 left
💡 Hint
Check if the function is declared async when using await.
✗ Incorrect
The function is not declared async but uses await, causing a SyntaxError.
❓ state_output
advanced2:00remaining
What is the rendered output of this server component with conditional data fetching?
Given this Next.js server component, what will it render?
NextJS
async function getData(flag) { if (flag) { return { message: 'Flag is true' }; } else { return null; } } export default async function Page() { const data = await getData(false); return <div>{data?.message ?? 'No data available'}</div>; }
Attempts:
2 left
💡 Hint
Optional chaining and nullish coalescing handle null data safely.
✗ Incorrect
getData returns null, so data is null. data?.message is undefined, so fallback 'No data available' is rendered.
🧠 Conceptual
expert2:00remaining
Which statement about data fetching in Next.js server components is TRUE?
Select the correct statement regarding data fetching in Next.js server components.
Attempts:
2 left
💡 Hint
Think about how server components handle data fetching compared to client components.
✗ Incorrect
Server components run on the server and can use async/await and fetch directly. They do not use React hooks like useState or useEffect, which are client-side only. Data fetching can be dynamic at request time. They do not require client components for data fetching.