Challenge - 5 Problems
Next.js Static Paths Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this GenerateStaticParams function output?
Consider this Next.js function that generates static paths for a blog. What will be the output of
generateStaticParams()?NextJS
export async function generateStaticParams() { const posts = [{ id: 'a' }, { id: 'b' }, { id: 'c' }]; return posts.map(post => ({ id: post.id })); }
Attempts:
2 left
💡 Hint
Remember that generateStaticParams returns an array of objects matching the dynamic segment keys.
✗ Incorrect
The function returns an array of objects with keys matching the dynamic route segment names. Here, the dynamic segment is 'id', so each object has an 'id' key.
📝 Syntax
intermediate2:00remaining
Which option correctly defines generateStaticParams for dynamic route [slug]?
You have a dynamic route page at
app/blog/[slug]/page.tsx. Which generateStaticParams function is syntactically correct and returns paths for slugs 'x' and 'y'?Attempts:
2 left
💡 Hint
The returned array should have objects with keys matching the dynamic segment name.
✗ Incorrect
The correct syntax returns an array of objects with keys matching the dynamic segment 'slug'. Option D matches this exactly.
🔧 Debug
advanced2:00remaining
Why does this generateStaticParams cause a build error?
Given this code, why does Next.js fail to build static paths?
export async function generateStaticParams() {
const data = await fetch('https://api.example.com/items');
return data.map(item => ({ id: item.id }));
}Attempts:
2 left
💡 Hint
Check what fetch returns and how to get JSON data from it.
✗ Incorrect
fetch returns a Response object. You must call response.json() to get the actual data array before mapping.
❓ state_output
advanced2:00remaining
What is the value of paths generated by this generateStaticParams?
Analyze this code snippet and determine the array returned by generateStaticParams:
export async function generateStaticParams() {
const ids = ['1', '2'];
return ids.flatMap(id => [{ id }, { id: id + '-extra' }]);
}Attempts:
2 left
💡 Hint
flatMap combines arrays returned by the callback into one array.
✗ Incorrect
flatMap calls the callback for each id and concatenates the arrays returned. So for '1' it returns [{id:'1'}, {id:'1-extra'}], same for '2'.
🧠 Conceptual
expert2:00remaining
Which statement about generateStaticParams in Next.js is true?
Select the correct statement about the behavior and usage of generateStaticParams in Next.js App Router.
Attempts:
2 left
💡 Hint
Think about when generateStaticParams runs and the shape of its return value in Next.js 13+ App Router.
✗ Incorrect
In Next.js App Router, generateStaticParams runs at build time and returns an array of objects with keys matching dynamic segments directly, no 'params' wrapper.