0
0
NextJSframework~20 mins

When to keep components on server in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Server Component Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why keep a component on the server in Next.js?
In Next.js, what is a main reason to keep a component rendered on the server instead of the client?
ATo improve SEO by rendering content before it reaches the browser
BTo allow users to interact with the component faster on their device
CTo enable client-side state updates without page reloads
DTo reduce server load by moving rendering to the client
Attempts:
2 left
💡 Hint
Think about what search engines see when content is server-rendered.
component_behavior
intermediate
2:00remaining
What happens if a server component tries to use client hooks?
Consider a Next.js server component that tries to use useState hook. What will happen?
AIt will run but state updates will be ignored
BIt will work normally and update state on the server
CIt will convert the component automatically to a client component
DIt will cause a build error because server components cannot use client hooks
Attempts:
2 left
💡 Hint
Remember which hooks are allowed only in client components.
state_output
advanced
2:00remaining
State behavior in server vs client components
Given a Next.js app with a server component rendering a client component inside it, where is the state stored and updated?
AState is stored and updated only in the client component on the browser
BState is stored on the server and updates cause server re-renders
CState is shared between server and client components automatically
DState is stored in the server component and passed down as props
Attempts:
2 left
💡 Hint
Think about where hooks like useState run.
📝 Syntax
advanced
2:00remaining
Correct syntax to mark a component as client in Next.js
Which of the following is the correct way to mark a React component as a client component in Next.js 14+?
AAdding <ClientOnly> wrapper around the component
BUsing the client: true property in the component export
C"use client"; at the top of the component file
DNaming the file with .client.js extension
Attempts:
2 left
💡 Hint
Look for the special directive string.
🔧 Debug
expert
3:00remaining
Why does this server component fail to render?
This Next.js server component imports a client component but does not mark it correctly. What error will occur?
NextJS
import ClientButton from './ClientButton';

export default function ServerComp() {
  return <ClientButton />;
}
ANo error, component renders normally
BBuild error: Client component imported into server component without "use client" directive
CWarning: Client component should not be nested inside server component
DRuntime error: ClientButton is undefined
Attempts:
2 left
💡 Hint
Check if the client component file has the correct directive.