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 output of this Next.js Server Component?
Consider this Next.js Server Component code. What will it render on the page?
NextJS
export default function Greeting() { const name = 'Alice'; return <h1>Hello, {name}!</h1>; }
Attempts:
2 left
💡 Hint
Server components run on the server and can use variables directly in JSX.
✗ Incorrect
The component runs on the server, so the variable 'name' is available and rendered as 'Alice'.
❓ lifecycle
intermediate2:00remaining
When does a Next.js Server Component run?
At what point does a Next.js Server Component execute its code?
Attempts:
2 left
💡 Hint
Think about where server components run compared to client components.
✗ Incorrect
Server components run on the server during the initial request to generate HTML before sending it to the browser.
❓ state_output
advanced2:00remaining
What happens if you use useState in a Next.js Server Component?
Examine this code snippet. What will happen when this Server Component runs?
export default function Counter() {
const [count, setCount] = useState(0);
return
{count}
; }NextJS
export default function Counter() { const [count, setCount] = useState(0); return <p>{count}</p>; }
Attempts:
2 left
💡 Hint
Remember which hooks are allowed in Server Components.
✗ Incorrect
useState is a React hook that only works in Client Components, so using it in a Server Component causes a syntax error.
📝 Syntax
advanced2:00remaining
Which code correctly fetches data in a Next.js Server Component?
Choose the option that correctly fetches data inside a Server Component and renders it.
Attempts:
2 left
💡 Hint
Server Components can be async and await fetch calls.
✗ Incorrect
Option A correctly awaits the fetch and JSON parsing before rendering. Others misuse promises or methods.
🔧 Debug
expert2:00remaining
Why does this Server Component cause a hydration mismatch error?
This Server Component renders a random number:
export default function Random() {
const num = Math.random();
return
{num}
; } Why might this cause a hydration mismatch error in Next.js?NextJS
export default function Random() { const num = Math.random(); return <p>{num}</p>; }
Attempts:
2 left
💡 Hint
Think about how server-rendered HTML and client hydration must match exactly.
✗ Incorrect
The server renders one random number, but the client renders a different one during hydration, causing mismatch errors.