Consider this Next.js root layout component. What will be rendered inside the <body> tag?
export default function RootLayout({ children }) { return ( <html lang="en"> <head> <title>My App</title> </head> <body> <header>Header Content</header> {children} <footer>Footer Content</footer> </body> </html> ); }
Remember that the root layout wraps all pages and renders children inside the body.
The root layout component wraps the entire app. The {children} prop represents the page content. Header and footer are rendered around children inside the body.
Choose the option that correctly defines a root layout component in Next.js 14+ using the App Router.
The root layout must accept children as a prop and return an html structure.
Option A correctly defines a root layout with children prop and returns html and body tags wrapping children. Option A misses children prop. Option A misses children prop. Option A returns body without html tag.
At what point does the root layout component execute in the Next.js App Router lifecycle?
Think about how layouts persist across pages in Next.js App Router.
The root layout runs once on the server during the initial page load and is reused for client-side navigations to preserve state and improve performance.
Given this root layout code, why might Next.js show a hydration mismatch error?
export default function RootLayout({ children }) { const date = new Date().toLocaleString(); return ( <html lang="en"> <body> <p>Current time: {date}</p> {children} </body> </html> ); }
Think about what happens when server and client render different content.
The date string is generated at render time on server and client differently, causing the HTML to differ and triggering hydration mismatch errors.
In this root layout component, what will be the value of count after clicking the button twice?
'use client'; import { useState } from 'react'; export default function RootLayout({ children }) { const [count, setCount] = useState(0); return ( <html lang="en"> <body> <button onClick={() => setCount(count + 1)}>Increment</button> <p>Count: {count}</p> {children} </body> </html> ); }
Remember how useState updates state on button clicks.
Each click increments count by 1. After two clicks, count becomes 2 and is displayed.