Complete the code to import the main layout component from the app directory.
import Layout from './[1]/layout';
The app directory is the root for Next.js 14+ app router files, including layouts.
Complete the code to define a server component in Next.js app router.
export default function Home() {
return <main>[1]</main>;
}Server components return JSX elements directly, like <h1>Welcome</h1>.
Fix the error in the Next.js page component export.
const page = () => {
return <div>Hello World</div>;
};
export default [1];The exported component must match the declared function name exactly without parentheses.
Fill both blanks to create a client component with state in Next.js.
"use client"; import { [1] } from 'react'; export default function Counter() { const [count, setCount] = [2](0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
We import useState hook and call it as useState(0) to create state.
Fill all three blanks to create a dynamic route page that fetches data in Next.js.
export async function [1]({ params }) { const data = await fetch(`/api/[2]/${params.id}`); const item = await data.json(); return <div>{item.[3]</div>; }
In Next.js app router, dynamic route [id]/page.tsx exports an async Page function that receives { params } and can fetch data server-side. The API path is '/api/getData/[id]' and we display the 'name' property.