Challenge - 5 Problems
Async Server Components Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this async server component render?
Consider this Next.js async server component. What will it render on the page?
NextJS
import React from 'react'; async function fetchData() { return new Promise(resolve => setTimeout(() => resolve('Hello from server!'), 100)); } export default async function Greeting() { const message = await fetchData(); return <div>{message}</div>; }
Attempts:
2 left
💡 Hint
Remember that async server components can await promises before rendering.
✗ Incorrect
The component awaits fetchData() which resolves to 'Hello from server!'. So it renders that string inside a div.
❓ lifecycle
intermediate2:00remaining
When does this async server component fetch data?
Given this async server component, when is fetchData called?
NextJS
async function fetchData() { console.log('Fetching data'); return 'Data'; } export default async function DataComponent() { const data = await fetchData(); return <p>{data}</p>; }
Attempts:
2 left
💡 Hint
Async server components run on the server before sending HTML.
✗ Incorrect
Async server components run on the server either at build time or on each request, so fetchData is called then.
📝 Syntax
advanced2:00remaining
Which option correctly defines an async server component in Next.js?
Select the correct syntax for an async server component that fetches data and renders it.
Attempts:
2 left
💡 Hint
Remember to await fetch and then await the response.json() in async functions.
✗ Incorrect
Option D correctly awaits fetch, then awaits res.json(), then renders the message property.
🔧 Debug
advanced2:00remaining
Why does this async server component cause a runtime error?
Identify the cause of the runtime error in this async server component.
NextJS
export default async function BrokenComponent() { const data = fetch('https://api.example.com/data'); return <div>{data}</div>; }
Attempts:
2 left
💡 Hint
Check if fetch is awaited before accessing its result.
✗ Incorrect
fetch returns a Promise. Without await, data is a Promise object, which React cannot render causing runtime error.
🧠 Conceptual
expert2:00remaining
What is a key benefit of using async server components in Next.js?
Choose the most accurate benefit of async server components compared to client components.
Attempts:
2 left
💡 Hint
Think about where async server components run and how that affects loading.
✗ Incorrect
Async server components run on the server, so they can fetch data before sending HTML, which helps performance and SEO.