Complete the code to export a server component in Next.js.
export default function [1]() { return <h1>Hello from server!</h1> }
In Next.js, the default export named Page is recognized as a server component by default.
Complete the code to fetch data on the server side in a Next.js server component.
export default async function Page() { const data = await fetch([1]); return <div>{JSON.stringify(data)}</div> }/client/data is not a standard API route.Server components can fetch data from API routes or external endpoints using fetch.
Fix the error in the code to mark a component as a client component in Next.js.
"use client"; export default function [1]() { return <button>Click me</button> }
Page without client directive causes server rendering.Client components must be marked with "use client" and can have any name, but ClientComponent is a clear name here.
Fill both blanks to create a server component that renders a list from fetched data.
export default async function Page() {
const data = await fetch([1]);
const items = await data.json();
return <ul>{items.map(item => <li key={item.id}>[2]</li>)}</ul>;
}The server component fetches from /api/items and renders each item's name.
Fill all three blanks to create a client component with state and event handler in Next.js.
"use client"; import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState([1]); function handleClick() { setCount(count [2] 1); } return <button onClick=[3]>Count: {count}</button>; }
The client component initializes state to 0, increments count by 1 on click, and uses handleClick as event handler.