Complete the code to define a layout component that wraps page content.
export default function Layout({ children }) {
return <div [1]>{children}</div>;
}The layout uses a div with a class name to style and wrap the children content.
Complete the code to import the layout component in a Next.js page.
import [1] from '../components/Layout'; export default function Page() { return <[1]>Hello World</[1]>; }
The layout component is named Layout and must be imported and used with the same name.
Fix the error in the layout to avoid redundant rendering by using React Fragment shorthand (<>).
export default function Layout({ children }) {
return [1]{children}[1];
}Using <> (shorthand for React.Fragment) avoids adding extra nodes to the DOM, preventing redundant rendering wrappers.
Fill both blanks to create a layout that uses Next.js <head> and avoids re-rendering the header on page changes.
import Head from 'next/head'; export default function Layout({ children }) { return ( <> <Head> <title>[1]</title> </Head> <header>[2]</header> <main>{children}</main> </> ); }
The <Head> sets the page title once, and the header content is static to avoid re-rendering on navigation.
Fill all three blanks to create a layout that uses React context to avoid redundant rendering of user info and theme.
import { createContext, useContext } from 'react'; const UserContext = createContext(null); const ThemeContext = createContext('light'); export default function Layout({ children, user }) { return ( <UserContext.Provider value=[1]> <ThemeContext.Provider value=[2]> <div className=[3]> {children} </div> </ThemeContext.Provider> </UserContext.Provider> ); }
The layout provides user and theme context values to avoid passing props down repeatedly, reducing redundant rendering.