Complete the code to import the React hook needed for client-side state.
import React, { [1] } from 'react';
The useState hook is used to manage client-side state in React components.
Complete the code to mark a React component as a client component in Next.js.
"use client"; export default function MyComponent() { return <div>Hello from [1] component!</div>; }
Adding "use client"; at the top marks the file as a client component in Next.js.
Fix the error in the code by completing the import statement for a server component.
import [1] from 'next/headers'; export default function ServerComp() { return <h1>Server Component</h1>; }
The cookies import from 'next/headers' is used in server components to access cookies.
Fill both blanks to create a client component that uses state and an event handler.
"use client"; import React, { [1] } from 'react'; export default function Counter() { const [count, setCount] = [2](0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; }
The useState hook is imported and used to create state in the client component.
Fill all three blanks to create a server component that fetches data and a client component that uses it.
import ClientComp from './ClientComp'; export default async function ServerComp() { const data = await fetch('/api/data').then(res => res.json()); return ( <main> <h1>Data:</h1> <ClientComp [1]=[2] /> <p>Fetched on the [3]</p> </main> ); }
The server component passes the fetched data as a prop to the client component and notes that data was fetched on the server.