Challenge - 5 Problems
Server Component Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the rendered output of this Next.js server component?
Consider this server component in Next.js 14+ that fetches data and renders it. What will be the output when rendered?
NextJS
import React from 'react'; async function getData() { return { message: 'Hello from server!' }; } export default async function Greeting() { const data = await getData(); return <h1>{data.message}</h1>; }
Attempts:
2 left
💡 Hint
Server components can use async/await to fetch data before rendering.
✗ Incorrect
The server component uses async/await to fetch data and renders the message inside an h1 tag. This is valid in Next.js 14+ server components.
❓ lifecycle
intermediate1:30remaining
When does a Next.js server component run its code?
In Next.js 14+, when does the code inside a server component execute?
Attempts:
2 left
💡 Hint
Server components run where the server renders the page.
✗ Incorrect
Server components run only on the server during initial rendering and server-side navigations. They do not run on the client.
🔧 Debug
advanced2:30remaining
Why does this server component cause a hydration mismatch?
Examine this server component code. Why does it cause a hydration mismatch error in Next.js?
NextJS
import React from 'react'; export default function Time() { const now = new Date().toISOString(); return <p>{now}</p>; }
Attempts:
2 left
💡 Hint
Server components render once on the server, but client hydration expects stable output.
✗ Incorrect
Using Date.now() or new Date() directly in server components causes the rendered HTML to differ from client hydration, leading to mismatch errors.
📝 Syntax
advanced3:00remaining
Which option correctly defines a server component with a server action in Next.js 14+?
Select the correct syntax for a server component that includes a server action to handle a form submission.
Attempts:
2 left
💡 Hint
Server actions require the 'use server' directive inside the function and must be async.
✗ Incorrect
Option B correctly marks the submit function as async and includes the 'use server' directive, enabling server action usage in Next.js 14+.
❓ state_output
expert3:00remaining
What is the value of count after rendering this mixed server/client component setup?
Given this Next.js 14+ setup with a server component rendering a client component, what is the final count value displayed after clicking the button twice?
NextJS
import React, { useState } from 'react'; // Client component 'use client'; export function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; } // Server component export default function Page() { return <Counter />; }
Attempts:
2 left
💡 Hint
Client components manage state and update on user interaction.
✗ Incorrect
The Counter is a client component with useState. Clicking twice increments count from 0 to 2, so the displayed value is 'Count: 2'.