Consider this Next.js Server Component code snippet. What will it render on the page?
export default function Greeting() { const hour = new Date().getHours(); return ( <main> <h1>{hour < 12 ? 'Good morning' : 'Good afternoon'}</h1> </main> ); }
Think about when Server Components run and what JavaScript features they can use.
Server Components run on the server and can use standard JavaScript like Date(). The component returns 'Good morning' if the hour is before 12, otherwise 'Good afternoon'.
Given this React functional component using hooks, what will be the displayed count after clicking the button two times?
import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); function handleClick() { setCount(count + 1); setCount(count + 1); } return ( <div> <p>Count: {count}</p> <button onClick={handleClick}>Increment Twice</button> </div> ); }
Remember how React batches state updates and how the current state value is captured in closures.
Both setCount calls use the same stale count value (0), so the count only increments once to 1 after the button click.
Next.js supports dynamic imports with React suspense. Which code snippet correctly implements this?
Check how suspense option and React.Suspense wrapper are used together.
Option A correctly enables suspense in dynamic import and wraps the component in React.Suspense with a fallback.
Examine the code below. Why does the build fail with the given error?
'use client'; import React from 'react'; export default function Page() { return <h1>Hello from Server Component</h1>; }
Think about what 'use client' means and when it should be used.
The 'use client' directive marks a component as client-side. If the component does not use client features, Next.js expects it to be a Server Component and fails the build.
Why does Next.js create multiple JavaScript chunks instead of one big file in the build output?
Think about user experience and network efficiency.
Splitting code into chunks allows Next.js to load only the code needed for the current page, speeding up load times and reducing bandwidth.