0
0
NextJSframework~5 mins

Data fetching in server components in NextJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a server component in Next.js?
A server component is a React component that runs only on the server. It can fetch data directly and send fully rendered HTML to the client, improving performance and SEO.
Click to reveal answer
beginner
How do you fetch data in a Next.js server component?
You fetch data by calling async functions directly inside the server component. Since it runs on the server, you can use native fetch or database queries without extra client-side code.
Click to reveal answer
intermediate
Why should you avoid fetching data inside client components in Next.js when using server components?
Fetching data in client components adds extra client-side loading and delays. Server components fetch data once on the server, sending ready HTML to the client for faster load and better SEO.
Click to reveal answer
intermediate
What happens if you use 'useEffect' to fetch data in a server component?
'useEffect' does not run in server components because it only runs in the browser. Data fetching in server components should be done with async/await directly in the component code.
Click to reveal answer
beginner
Can server components fetch data from external APIs and databases?
Yes, server components can fetch data from any source like external APIs or databases because they run on the server and have full access to backend resources.
Click to reveal answer
Where does data fetching happen in Next.js server components?
ADirectly inside the server component using async functions
BInside useEffect hook
COnly in client components
DUsing Redux actions
Why is data fetching in server components better for SEO?
ABecause client components load faster
BBecause the server sends fully rendered HTML with data
CBecause it uses useEffect
DBecause it avoids server rendering
What happens if you try to use 'useEffect' in a server component?
AIt fetches data immediately
BIt causes a server error
CIt does not run because useEffect only works in the browser
DIt runs on the server and client
Which of these is a benefit of fetching data in server components?
AFaster page load with ready HTML
BMore client-side JavaScript
CDelayed rendering
DRequires Redux
Can server components access databases directly?
AOnly if using Redux
BNo, only client components can
COnly with special APIs
DYes, because they run on the server
Explain how data fetching works in Next.js server components and why it improves performance.
Think about where the code runs and what the client receives.
You got /4 concepts.
    Describe the difference between fetching data in server components versus client components in Next.js.
    Consider timing and where the data is fetched.
    You got /4 concepts.