Complete the code to create a Next.js page component that renders a heading.
export default function Home() {
return (
<main>
<h1>[1]</h1>
</main>
)
}The heading text must be a string inside quotes in JSX.
Complete the code to import the Next.js Link component for navigation.
import [1] from 'next/link';
Next.js uses the Link component from 'next/link' for client-side navigation.
Fix the error in this Next.js server component export statement.
export default function [1]() { return <div>Hello Next.js</div>; }
In Next.js App Router, the default export for a page file must be named page (lowercase) to be recognized as a server component.
Fill both blanks to create a server action that updates state and triggers a re-render.
import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); async function increment() { await [1](count + 1); } return ( <button onClick=[2]>Count: {count}</button> ); }
The increment function calls setCount to update state. The button's onClick needs a function, so we pass () => increment().
Fill all three blanks to create a Next.js API route handler that returns JSON.
export async function [1](req, res) { const data = { message: 'Hello from API' }; res.[2](200).[3](data); }
Next.js API routes export HTTP method functions like GET. The response uses status(200) to set status and json(data) to send JSON.