0
0
NextJSframework~20 mins

How Next.js renders (server-first model) - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Server-First Mastery
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 Next.js Server Component?
Consider this Next.js Server Component that fetches data and renders it. What will the user see when this component is 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>;
}
A<h1>undefined</h1>
B<h1>Loading...</h1>
CError: Cannot use await in component
D<h1>Hello from server!</h1>
Attempts:
2 left
💡 Hint
Remember that Next.js Server Components can use async/await to fetch data before rendering.
lifecycle
intermediate
1:30remaining
When does Next.js Server Component code run?
In Next.js's server-first rendering model, when does the code inside a Server Component execute?
ABoth on server and client simultaneously
BOnly on the client after hydration
COnly on the server during the initial page request
DOnly when the user interacts with the component
Attempts:
2 left
💡 Hint
Think about where server components run and when the HTML is generated.
📝 Syntax
advanced
2:00remaining
Which option correctly defines a Next.js Client Component?
Next.js uses special syntax to mark Client Components. Which of these options correctly marks a component as a Client Component?
A
"use client";
export default function MyComponent() { return &lt;div&gt;Client&lt;/div&gt;; }
Bexport const MyComponent = () => { return <div>Client</div>; };
C
"use server";
export default function MyComponent() { return &lt;div&gt;Client&lt;/div&gt;; }
Dexport default function MyComponent() { return <div>Client</div>; }
Attempts:
2 left
💡 Hint
Client Components require a special directive at the top of the file.
🔧 Debug
advanced
2:00remaining
Why does this Next.js Server Component cause a runtime error?
Examine this Server Component code. Why will it cause an error when rendered?
NextJS
import React from 'react';

export default function ServerComp() {
  const [count, setCount] = React.useState(0);
  return <div>{count}</div>;
}
AReact is not imported
BuseState cannot be used in Server Components
CMissing async keyword on the function
DNo error, code runs fine
Attempts:
2 left
💡 Hint
Think about hooks and where they can be used in Next.js components.
🧠 Conceptual
expert
2:30remaining
How does Next.js handle data fetching in Server Components for SEO and performance?
Which statement best describes how Next.js Server Components improve SEO and performance through data fetching?
AData is fetched on the server before rendering, so HTML sent to the client includes all data, improving SEO and load speed
BNext.js does not support data fetching in Server Components
CData is fetched both on server and client simultaneously to balance SEO and speed
DData is fetched on the client after page load, improving interactivity but delaying SEO content
Attempts:
2 left
💡 Hint
Think about when the HTML is generated and what the client receives.