0
0
NextJSframework~20 mins

Page.tsx as route definition in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Page Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1: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>;
}
A<main><h1>Welcome to Next.js 14!</h1><p>This is the home page.</p></main>
B<div><h1>Welcome to Next.js 14!</h1><p>This is the home page.</p></div>
C<main><h2>Welcome to Next.js 14!</h2><p>This is the home page.</p></main>
D<main><h1>Welcome!</h1><p>This is the home page.</p></main>
Attempts:
2 left
💡 Hint
Look carefully at the tags and text inside the returned JSX.
📝 Syntax
intermediate
1: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.
Aexport function Page() { return <div>Hello</div>; }
Bexport default const Page = () => <div>Hello</div>;
Cfunction Page() { return <div>Hello</div>; } export Page;
Dexport default function Page() { return <div>Hello</div>; }
Attempts:
2 left
💡 Hint
Next.js expects a default export for the page component.
state_output
advanced
2: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>
  );
}
A<main><p>Count: 1</p><button>Increment</button></main>
B<main><p>Count: 0</p><button>Increment</button></main>
C<main><p>Count: NaN</p><button>Increment</button></main>
D<main><p>Count: -1</p><button>Increment</button></main>
Attempts:
2 left
💡 Hint
The button increases count by 1 on each click.
lifecycle
advanced
1: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>;
}
AEvery time the user clicks anywhere on the page.
BEvery time the component re-renders.
COnly once after the component first renders on the client.
DOnly on the server during initial render.
Attempts:
2 left
💡 Hint
An empty dependency array means the effect runs once after mount.
🔧 Debug
expert
2: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>
  );
}
AThe variable 'message' is not declared.
BThe method 'toUppercase' is not defined on string, should be 'toUpperCase'.
CJSX elements must have a single parent element.
DThe function is missing a return statement.
Attempts:
2 left
💡 Hint
Check the spelling of string methods used inside JSX.