Complete the code to import the Next.js Image component correctly.
import [1] from 'next/image';
The Next.js Image component is imported as Image from 'next/image'. This component helps optimize images automatically.
Complete the code to use the Next.js Image component with a fixed width and height.
<Image src="/logo.png" alt="Logo" width=[1] height={50} />
The width and height props expect numbers, not strings with units. So use 100 without quotes or units.
Fix the error in the Next.js API route handler to send a JSON response.
export default function handler(req, res) {
res.[1]({ message: 'Hello' });
}In Next.js API routes, res.json() sends a JSON response properly.
Fill both blanks to create a dynamic route in Next.js that fetches data based on the URL parameter.
export async function getServerSideProps(context) {
const id = context.params.[1];
const res = await fetch(`https://api.example.com/data/$[2]`);
const data = await res.json();
return { props: { data } };
}The URL parameter is accessed via context.params.id, and the same id is used in the fetch URL.
Fill all three blanks to optimize a Next.js page by using React's useMemo hook to memoize a computed value.
import { useMemo } from 'react'; export default function Page({ items }) { const total = useMemo(() => items.[1]((sum, item) => sum [2] item.value, [3]), [items]); return <div>Total: {total}</div>; }
Use reduce to sum values, + as the operator, and 0 as the initial sum value. useMemo memoizes this calculation for performance.