Challenge - 5 Problems
Next.js Page Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What does this Next.js Page component render?
Consider this Next.js 14 Page.tsx file in the app directory. What will the user see when visiting this route?
NextJS
export default function Page() { return <main><h1>Welcome to Next.js 14!</h1><p>This is the home page.</p></main>; }
Attempts:
2 left
💡 Hint
Look carefully at the tags and text inside the returned JSX.
✗ Incorrect
The component returns a element with an
containing exactly 'Welcome to Next.js 14!' and a
with 'This is the home page.'. Only option A matches this exactly.
📝 Syntax
intermediate1:30remaining
Which option correctly exports a Next.js Page component in TypeScript?
Choose the correct way to define and export a Page component in Next.js 14 using TypeScript.
Attempts:
2 left
💡 Hint
Next.js expects a default export for the page component.
✗ Incorrect
Option D correctly defines and exports the Page component as the default export. Option D exports a named function, which Next.js does not recognize as a route. Option D has invalid export syntax. Option D has invalid syntax mixing export default and const.
❓ state_output
advanced2:00remaining
What is the rendered output after clicking the button?
This Next.js Page component uses React state. What text is shown after clicking the button once?
NextJS
import { useState } from 'react'; export default function Page() { const [count, setCount] = useState(0); return ( <main> <p>Count: {count}</p> <button onClick={() => setCount(count + 1)}>Increment</button> </main> ); }
Attempts:
2 left
💡 Hint
The button increases count by 1 on each click.
✗ Incorrect
Initially count is 0. Clicking the button calls setCount(count + 1), so count becomes 1. The rendered text updates to 'Count: 1'.
❓ lifecycle
advanced1:30remaining
When does the useEffect run in this Next.js Page component?
Given this component, when will the console.log inside useEffect execute?
NextJS
import { useEffect } from 'react'; export default function Page() { useEffect(() => { console.log('Page mounted'); }, []); return <main><h1>Hello</h1></main>; }
Attempts:
2 left
💡 Hint
An empty dependency array means the effect runs once after mount.
✗ Incorrect
useEffect with an empty dependency array runs only once after the component mounts on the client side. It does not run on server or on re-renders.
🔧 Debug
expert2:30remaining
Why does this Next.js Page component cause a runtime error?
Examine this Page.tsx code. What causes the error when visiting this route?
NextJS
export default function Page() { const message = 'Hello'; return ( <main> <h1>{message.toUppercase()}</h1> </main> ); }
Attempts:
2 left
💡 Hint
Check the spelling of string methods used inside JSX.
✗ Incorrect
JavaScript strings have a method 'toUpperCase' with a capital 'C'. Using 'toUppercase' causes a runtime TypeError because it's undefined.