Challenge - 5 Problems
Dynamic Metadata Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this dynamic metadata function?
Consider this Next.js dynamic metadata function. What metadata will be generated for the page?
NextJS
export async function generateMetadata({ params }) { const { id } = params; return { title: `Post ${id}`, description: `Details about post ${id}`, }; } // Assume params = { id: '42' }
Attempts:
2 left
💡 Hint
Look at how the id from params is used inside the template strings.
✗ Incorrect
The function uses the id parameter to create a title and description dynamically. For id '42', it returns title 'Post 42' and description 'Details about post 42'.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in generateMetadata?
Identify which generateMetadata function code snippet will cause a syntax error in Next.js.
Attempts:
2 left
💡 Hint
Check for missing closing braces or parentheses.
✗ Incorrect
Option B is missing the closing brace for the function, causing a syntax error.
❓ state_output
advanced2:00remaining
What metadata is generated when params.slug is undefined?
Given this generateMetadata function, what will be the output if params.slug is undefined?
NextJS
export async function generateMetadata({ params }) { return { title: `Page ${params.slug || 'default'}`, description: `Content for ${params.slug || 'default'}` }; }
Attempts:
2 left
💡 Hint
Look at the fallback value used with || operator.
✗ Incorrect
If params.slug is undefined, the || operator uses 'default' as fallback, so title and description include 'default'.
🔧 Debug
advanced2:00remaining
Why does this generateMetadata function cause a runtime error?
Examine the code and identify the cause of the runtime error when generateMetadata is called.
NextJS
export async function generateMetadata({ params }) { const data = await fetch(`https://api.example.com/posts/${params.id}`); const post = await data.json(); return { title: post.title, description: post.summary }; } // Assume params.id is undefined
Attempts:
2 left
💡 Hint
Check the URL used in fetch and the value of params.id.
✗ Incorrect
If params.id is undefined, the fetch URL becomes invalid, causing a network error at runtime.
🧠 Conceptual
expert2:00remaining
Which option best describes the purpose of generateMetadata in Next.js dynamic routes?
Select the most accurate description of what generateMetadata does in Next.js dynamic routes.
Attempts:
2 left
💡 Hint
Think about when and how metadata changes for dynamic routes.
✗ Incorrect
generateMetadata runs on the server for each dynamic route to produce metadata based on route params, enabling dynamic SEO tags.