Complete the code to export a server component in Next.js.
export default function Home() {
return <h1>Hello from [1] component!</h1>;
}Server components in Next.js are default exports without the 'use client' directive.
Complete the code to import a client component inside a server component.
import ClientButton from './ClientButton'; export default function ServerPage() { return <div><[1] /></div>; }
Server components can import and render client components by referencing their correct names.
Fix the error in the server component by completing the code to fetch data correctly.
export default async function DataPage() {
const res = await fetch('/api/data', { cache: '[1]' });
const data = await res.json();
return <pre>{JSON.stringify(data)}</pre>;
}Server components should use 'no-store' to avoid caching when fetching dynamic data.
Fill both blanks to correctly mark a component as client and use state in Next.js.
"use [1]"; import { [2] } from 'react'; export default function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
Client components must start with 'use client' and import 'useState' to manage state.
Fill all three blanks to create a server component that fetches data and renders a list.
export default async function UsersList() {
const res = await fetch('[1]', { cache: '[2]' });
const users = await res.json();
return (
<ul>
{users.map(user => <li key={user.id}>[3]</li>)}
</ul>
);
}The server component fetches from '/api/users' with 'no-store' cache and renders each user's name.