15.
What is the output of the following Next.js code?
import React from 'react';
import { useRouter } from 'next/router';
const MyPage = () => {
const router = useRouter();
const { id } = router.query;
return <h1>{id}</h1>;
};
export default MyPage;
An error will occur, as the id variable is not defined.
It outputs MyPage
The HTML <h1> element with the value of the id parameter from the query string.
It outputs router.query
Correct: C
The code imports the useRouter hook from Next.js, which provides access to the router object. In this code, the id variable is extracted from the router.query object, which contains the query parameters from the URL. The value of id is then rendered inside an <h1> element, so the output will be an HTML element containing the value of the id parameter from the query string.