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 output does this Server Component produce?
Consider this Next.js Server Component code. What will it render on the page?
NextJS
export default async function Greeting() { const name = await Promise.resolve('Alice'); return <h1>Hello, {name}!</h1>; }
Attempts:
2 left
💡 Hint
Server Components can use async/await to fetch data before rendering.
✗ Incorrect
Server Components can run async code and resolve promises before rendering. Here, the awaited name 'Alice' is inserted into the output.
📝 Syntax
intermediate2:00remaining
Which code snippet is valid inside a Next.js Server Component?
Select the code snippet that is valid and will not cause a syntax or runtime error in a Server Component.
Attempts:
2 left
💡 Hint
Server Components support async/await and Node.js APIs but do not support hooks like useState.
✗ Incorrect
Option D correctly uses import and await with fs.promises in a Server Component. Option D uses require which is not supported in ES modules. Option D does not await the promise, so data is a Promise object. Option D uses useState which is a Client Component hook and not allowed in Server Components.
🔧 Debug
advanced2:00remaining
Why does this Server Component cause a runtime error?
Analyze the code below. Why will this Server Component cause an error when rendering?
NextJS
import { useState } from 'react'; export default function Counter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
Attempts:
2 left
💡 Hint
Server Components cannot use React hooks that require client-side interactivity.
✗ Incorrect
useState is a React hook that only works in Client Components. Using it in a Server Component causes a runtime error because Server Components do not support state or event handlers.
🧠 Conceptual
advanced2:00remaining
Which of these can run inside a Next.js Server Component?
Select the option that correctly describes what can run inside a Server Component.
Attempts:
2 left
💡 Hint
Think about what runs on the server vs what runs in the browser.
✗ Incorrect
Server Components run on the server and can use async/await, Node.js APIs, and render JSX. They cannot use client-side hooks or browser APIs or event handlers.
❓ state_output
expert3:00remaining
What is the output of this mixed Server and Client Component setup?
Given the code below, what will be rendered on the page?
NextJS
import ClientCounter from './ClientCounter'; export default async function Page() { const message = await Promise.resolve('Welcome'); return ( <> <h1>{message}</h1> <ClientCounter /> </> ); } // ClientCounter.jsx 'use client'; import { useState } from 'react'; export default function ClientCounter() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; }
Attempts:
2 left
💡 Hint
Server Components can render Client Components which handle state and events.
✗ Incorrect
The Server Component renders the awaited message and includes the Client Component. The Client Component uses useState and event handlers, so the button is interactive and shows count starting at 0.