Complete the code to mark a React component as a client component in Next.js.
"use client"; export default function Button() { return <button>[1]Click me</button>; }
Client components handle interactivity, so you add event handlers like onClick to respond to user actions.
Complete the code to import the React hook needed for state in a client component.
"use client"; import [1] from 'react'; export default function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
Client components use useState to manage interactive state like counters.
Fix the error in the client component by adding the missing directive.
export default function Clicker() {
const [clicked, setClicked] = useState(false);
return <button onClick={() => setClicked(true)}>Click me</button>;
}
// Missing something here: [1]Client components in Next.js must start with "use client"; to enable interactivity.
Fill both blanks to complete a client component that updates state on button click.
"use client"; import { [1] } from 'react'; export default function Toggle() { const [on, setOn] = [2](false); return <button onClick={() => setOn(!on)}>{on ? 'On' : 'Off'}</button>; }
The useState hook is imported and used to create state in client components.
Fill all three blanks to create a client component that tracks input text and displays it.
"use client"; import { [1] } from 'react'; export default function TextInput() { const [text, setText] = [2](''); return ( <> <input type="text" value={text} onChange={e => setText(e.target.[3])} /> <p>You typed: {text}</p> </> ); }
The useState hook manages the text state, and value gets the input's current value from the event.