Challenge - 5 Problems
Next.js Interleaving Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What will this Next.js component render?
Consider this Next.js 14 component using server and client code interleaving. What will be the rendered output in the browser?
NextJS
import { cookies } from 'next/headers'; export default function Greeting() { const cookieStore = cookies(); const user = cookieStore.get('user')?.value ?? 'Guest'; return ( <main> <h1>Hello, {user}!</h1> <ClientButton /> </main> ); } 'use client'; import { useState } from 'react'; function ClientButton() { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + 1)} aria-label="Increment count"> Clicked {count} times </button> ); }
Attempts:
2 left
💡 Hint
Remember that cookies() runs on the server and returns cookie values if present, otherwise fallback is used.
✗ Incorrect
The server component reads cookies on the server side. If no 'user' cookie is set, it defaults to 'Guest'. The client component renders a button with initial count 0.
❓ state_output
intermediate1:30remaining
What is the button label after clicking twice?
Given this Next.js client component inside a server component, what will the button label show after clicking it twice?
NextJS
'use client'; import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); return ( <button onClick={() => setCount(count + 1)} aria-label="Increment"> Clicked {count} times </button> ); }
Attempts:
2 left
💡 Hint
Each click increments the count state by 1.
✗ Incorrect
The useState hook starts count at 0. Each click adds 1, so after two clicks, count is 2.
📝 Syntax
advanced2:00remaining
Which option correctly imports and uses a client component inside a server component?
In Next.js 14, you want to use a client component named inside a server component. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Server components do not have 'use client' directive. Client components must have it.
✗ Incorrect
Server components can import client components without 'use client' directive themselves. The client component file must have 'use client'.
🔧 Debug
advanced2:30remaining
Why does this Next.js component cause a hydration error?
This Next.js component mixes server and client code. Why does it cause a hydration mismatch error in the browser?
Code:
import { cookies } from 'next/headers';
export default function Page() {
const user = cookies().get('user')?.value ?? 'Guest';
return (
);
}
Welcome, {user}
Attempts:
2 left
💡 Hint
Client interactivity requires 'use client' directive on the component or a child component.
✗ Incorrect
Server components cannot have event handlers like onClick directly. The button with onClick must be in a client component with 'use client' directive to avoid hydration mismatch.
🧠 Conceptual
expert2:00remaining
What is the main benefit of interleaving server and client components in Next.js 14?
Next.js 14 allows mixing server and client components in the same UI tree. What is the primary advantage of this approach?
Attempts:
2 left
💡 Hint
Think about balancing performance and interactivity in modern web apps.
✗ Incorrect
Interleaving lets Next.js render static or data-heavy parts on the server for speed, while client components handle user interaction, giving best of both worlds.