getServerSideProps must be an async function exported with the exact name.
Step 2: Check return structure
It returns an object with a props key containing data for the page.
Final Answer:
export async function getServerSideProps(context) { return { props: {} } } -> Option B
Quick Check:
Correct async export with props = D [OK]
Hint: Use async function with named export and return props [OK]
Common Mistakes:
Using arrow function without export keyword
Returning object without wrapping props
Using default export incorrectly
3. Given this code snippet in a Next.js page, what will be the rendered output?
export async function getServerSideProps() {
return { props: { message: 'Hello from server' } };
}
export default function Page({ message }) {
return <h1>{message}</h1>;
}
medium
A. <h1>Hello from server</h1>
B. Error: message is undefined
C. <h1>{message}</h1>
D. <h1>Hello from client</h1>
Solution
Step 1: Understand data flow
getServerSideProps passes message as a prop to the page component.
Step 2: Render output
The component receives message and renders it inside an <h1> tag.
Final Answer:
<h1>Hello from server</h1> -> Option A
Quick Check:
Server prop passed and rendered = A [OK]
Hint: Props from server appear as component parameters [OK]
Common Mistakes:
Thinking props are undefined without client fetch
Rendering literal {message} instead of value
Confusing server message with client message
4. What is wrong with this getServerSideProps function?
export async function getServerSideProps() {
const data = await fetch('https://api.example.com/data');
return data;
}
medium
A. The returned props must be an object with a props key wrapping data
B. The fetch call is missing await
C. getServerSideProps cannot be async
D. The function should return data directly, not inside props
Solution
Step 1: Check fetch usage
The fetch is awaited correctly, so no issue there.
Step 2: Check return structure
The function must return an object with a props key containing an object. Here, data is returned directly, which is incorrect.
Final Answer:
The returned props must be an object with a props key wrapping data -> Option A
Quick Check:
Return { props: { ... } } not just data [OK]
Hint: Always wrap data inside props object in return [OK]
Common Mistakes:
Returning data directly instead of inside props
Forgetting to await fetch
Thinking async is not allowed
5. You want to pass user data fetched from a database to a Next.js page using getServerSideProps. Which approach correctly handles the asynchronous fetch and passes the data safely to the page component?
hard
A. export async function getServerSideProps() {
const user = getUserFromDB();
return { props: user };
}
B. export function getServerSideProps() {
const user = getUserFromDB();
return { props: { user } };
}
C. export async function getServerSideProps() {
const user = await getUserFromDB();
return { props: { user } };
}
D. export async function getServerSideProps() {
const user = await getUserFromDB();
return user;
}
Solution
Step 1: Handle async data fetching
The function must be async and await the database call to get user data.
Step 2: Return data wrapped in props object
The returned object must have a props key containing an object with user data.
Final Answer:
export async function getServerSideProps() {
const user = await getUserFromDB();
return { props: { user } };
} -> Option C
Quick Check:
Async await + return props object = C [OK]
Hint: Await async fetch and wrap result inside props [OK]
Common Mistakes:
Not awaiting async database call
Returning data directly without props wrapper
Using non-async function for async fetch
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.