0
0
NextJSframework~5 mins

Server component restrictions in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a key restriction of Next.js Server Components regarding browser APIs?
Server Components cannot use browser-only APIs like window, document, or localStorage because they run on the server, not in the browser.
Click to reveal answer
beginner
Can Server Components in Next.js use React hooks like useState or useEffect?
No, Server Components cannot use client-only React hooks such as useState or useEffect because they do not run in the browser and have no state or lifecycle.
Click to reveal answer
intermediate
Why can't Server Components import client components directly in Next.js?
Server Components can import client components, but client components must be marked with <code>"use client"</code>. This keeps server and client code separate.
Click to reveal answer
beginner
What kind of data fetching is recommended inside Next.js Server Components?
Server Components can fetch data directly using async/await because they run on the server, allowing secure and fast data fetching without exposing secrets to the client.
Click to reveal answer
beginner
Explain why Server Components cannot have event handlers like onClick.
Event handlers like onClick require client-side JavaScript to run. Server Components render HTML on the server and do not handle client events, so event handlers must be in Client Components.
Click to reveal answer
Which of the following is NOT allowed inside a Next.js Server Component?
ARendering JSX
BFetching data with async/await
CUsing <code>window</code> object
DImporting other Server Components
Can you use React's useState hook inside a Server Component?
ANo, never
BOnly if marked with "use client"
CYes, always
DOnly in Next.js 12
How do you mark a component as a Client Component in Next.js?
AUse <code>React.useClient()</code>
BAdd <code>"use client"</code> at the top of the file
CName the file with .client.js extension
DWrap component in <Client> tag
Why can't Server Components handle user events like clicks?
AThey don't render HTML
BThey only handle data fetching
CThey are deprecated
DThey run only on the server without client JavaScript
Which is a benefit of Server Components in Next.js?
AThey enable secure server-side data fetching
BThey run faster in the browser
CThey replace Client Components completely
DThey allow direct access to browser APIs
Describe the main restrictions of Next.js Server Components and why they exist.
Think about where Server Components run and what that means for code they can use.
You got /5 concepts.
    Explain how Server Components and Client Components work together in Next.js.
    Consider the roles of server and client in a web app.
    You got /5 concepts.