0
0
NextJSframework~20 mins

GenerateStaticParams for static paths in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Static Paths Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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 }));
}
A[{ id: 'a' }, { id: 'b' }, { id: 'c' }]
B[{ params: { postId: 'a' } }, { params: { postId: 'b' } }, { params: { postId: 'c' } }]
C[{ id: 'a' }, { id: 'b' }, { id: 'c' }, { params: { id: 'a' } }]
D[{ params: { id: 'a' } }, { params: { id: 'b' } }, { params: { id: 'c' } }]
Attempts:
2 left
💡 Hint
Remember that generateStaticParams returns an array of objects matching the dynamic segment keys.
📝 Syntax
intermediate
2: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'?
A
export async function generateStaticParams() {
  return [{ params: { slug: 'x' } }, { params: { slug: 'y' } }];
}
B
export async function generateStaticParams() {
  return [{ slug: 'x' }, { slug: 'z' }];
}
C
export async function generateStaticParams() {
  return [{ slug: ['x', 'y'] }];
}
D
export async function generateStaticParams() {
  return [{ slug: 'x' }, { slug: 'y' }];
}
Attempts:
2 left
💡 Hint
The returned array should have objects with keys matching the dynamic segment name.
🔧 Debug
advanced
2: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 }));
}
ABecause the returned array must be wrapped inside a 'params' key.
BBecause generateStaticParams cannot be async.
CBecause fetch returns a Response object, not the parsed JSON array directly.
DBecause the dynamic segment is missing in the returned objects.
Attempts:
2 left
💡 Hint
Check what fetch returns and how to get JSON data from it.
state_output
advanced
2: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' }]);
}
A[{ id: '1' }, { id: '1-extra' }, { id: '2' }, { id: '2-extra' }]
B[{ id: '1' }, { id: '2' }]
C[{ id: '1-extra' }, { id: '2-extra' }]
D[{ id: '1' }, { id: '2' }, { id: '1-extra' }, { id: '2-extra' }]
Attempts:
2 left
💡 Hint
flatMap combines arrays returned by the callback into one array.
🧠 Conceptual
expert
2: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.
AgenerateStaticParams runs on every client request to fetch dynamic paths.
BgenerateStaticParams runs at build time and must return an array of objects matching dynamic route segments without wrapping in 'params'.
CgenerateStaticParams can only return a single object, not an array.
DgenerateStaticParams requires returning objects with a 'params' key wrapping the dynamic segments.
Attempts:
2 left
💡 Hint
Think about when generateStaticParams runs and the shape of its return value in Next.js 13+ App Router.