Recall & Review
beginner
What does the
use server directive do in Next.js?It marks a function or component to run only on the server side, ensuring it does not run in the browser. This helps with security and performance.
Click to reveal answer
beginner
Where should you place the
use server directive in your Next.js code?At the very top of the file or function before any other code, as a special directive line:
'use server'.Click to reveal answer
intermediate
Why is it important to use the
use server directive for server-only functions?It prevents server-only code from being bundled and sent to the browser, reducing bundle size and avoiding exposing sensitive logic.
Click to reveal answer
beginner
Can a component marked with
use server access browser APIs like window?No. Components or functions with
use server run only on the server and do not have access to browser-specific APIs.Click to reveal answer
intermediate
How does
use server relate to React Server Components in Next.js?It explicitly marks functions or components as server-only, which is a key part of React Server Components to separate server and client logic.
Click to reveal answer
What is the correct way to mark a function as server-only in Next.js?
✗ Incorrect
The 'use server' directive at the top of the file or function marks it as server-only.
What happens if you do NOT use 'use server' for a server-only function?
✗ Incorrect
Without 'use server', Next.js may include the function in client bundles, exposing server logic.
Can a 'use server' function use browser APIs like localStorage?
✗ Incorrect
'use server' functions run only on the server and cannot access browser APIs.
Where should the 'use server' directive be placed in a file?
✗ Incorrect
'use server' must be at the top of the file or function before any other code.
What is a benefit of using 'use server' in Next.js?
✗ Incorrect
'use server' helps keep server code off the client, reducing bundle size and improving security.
Explain what the 'use server' directive does in Next.js and why it is important.
Think about where your code runs and what you want to hide from the browser.
You got /3 concepts.
Describe how to correctly use the 'use server' directive in a Next.js component or function.
It's a special comment line that must come first.
You got /3 concepts.