Complete the code to define an async server component in Next.js.
export default async function [1]() { return <div>Hello from server component</div>; }
The default export function name is often Page in Next.js server components.
Complete the code to fetch data inside an async server component.
export default async function Page() {
const res = await fetch('[1]');
const data = await res.json();
return <div>{data.message}</div>;
}Using /api/message is a common local API route in Next.js for fetching data.
Fix the error in the async server component by completing the code.
export default [1] function Page() { const data = await fetch('/api/info').then(res => res.json()); return <div>{data.info}</div>; }
The component function must be marked async to use await inside it.
Fill both blanks to correctly fetch and display data in an async server component.
export default async function Page() {
const res = await fetch('[1]');
const data = await res.[2]();
return <div>{data.title}</div>;
}Use /api/posts as the fetch URL and json() to parse the response.
Fill all three blanks to create an async server component that fetches and renders a list.
export default async function Page() {
const res = await fetch('[1]');
const posts = await res.[2]();
return (
<ul>
{posts.[3](post => <li key={post.id}>{post.title}</li>)}
</ul>
);
}The component fetches from /api/posts, parses JSON, and maps over posts to render list items.
