0
0
NextJSframework~20 mins

Zero bundle size for server components in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Zero Bundle Size Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Server Component rendering?
Consider this Next.js Server Component code. What will be rendered in the browser?
NextJS
export default function Greeting() {
  const message = 'Hello from server!';
  return <h1>{message}</h1>;
}
A<h1>Hello from client!</h1>
B<h1>Hello from server!</h1>
CError: Cannot render on server
D<div>Hello from server!</div>
Attempts:
2 left
💡 Hint
Server Components render HTML on the server and send it as static markup.
state_output
intermediate
2:00remaining
What happens if you use useState in a Server Component?
Given this Server Component code, what will happen when you try to run it?
NextJS
import { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
ARuntime error: setCount is not a function
BThe component renders a button with 0 and updates count on click
CSyntaxError: useState cannot be used in Server Components
DThe component renders but count never updates on click
Attempts:
2 left
💡 Hint
Server Components do not support React hooks like useState.
📝 Syntax
advanced
2:00remaining
Which option correctly marks a component as a Server Component in Next.js?
Select the code snippet that correctly defines a Server Component with zero client bundle size.
A
import React from 'react';
export default function MyComponent() { return &lt;p&gt;Server&lt;/p&gt;; }
B
"use client";
export default function MyComponent() { return &lt;p&gt;Client&lt;/p&gt;; }
C
"use server";
export default function MyComponent() { return &lt;p&gt;Server&lt;/p&gt;; }
Dexport default function MyComponent() { return <p>Server</p>; }
Attempts:
2 left
💡 Hint
Server Components do not need a special directive; client components use "use client".
🔧 Debug
advanced
2:00remaining
Why does this Server Component cause a client bundle to be generated?
Analyze the code below. Why does it cause Next.js to include client-side JavaScript in the bundle?
NextJS
import { useState } from 'react';

export default function Example() {
  return <button onClick={() => alert('Clicked!')}>Click me</button>;
}
ABecause it uses an event handler onClick, which requires client-side JavaScript
BBecause alert is not allowed in Server Components
CBecause it imports useState, which is client-only, triggering client bundle
DBecause the component returns a button element
Attempts:
2 left
💡 Hint
Event handlers require client-side interactivity.
🧠 Conceptual
expert
3:00remaining
How does Next.js achieve zero bundle size for Server Components?
Choose the best explanation for how Next.js ensures Server Components have zero client bundle size.
ANext.js compiles Server Components to static HTML on the server and never sends their code to the client
BNext.js bundles Server Components with client code but disables their JavaScript execution on the client
CNext.js converts Server Components to client components at runtime to reduce bundle size
DNext.js uses a special runtime that runs Server Components inside the browser without bundling
Attempts:
2 left
💡 Hint
Think about where Server Components run and what is sent to the browser.