Bird
Raised Fist0
NextJSframework~20 mins

What is Next.js - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Next.js Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the primary purpose of Next.js?
Next.js is a popular framework built on top of React. What is its main purpose?
ATo provide server-side rendering and static site generation for React applications
BTo create mobile apps without using React Native
CTo manage databases directly within React apps
DTo replace React with a new UI library
Attempts:
2 left
💡 Hint
Think about how Next.js helps with rendering pages faster and improving SEO.
❓ component_behavior
intermediate
2:00remaining
What happens when you export a React component as default in a Next.js page?
In Next.js, you create a file under the 'app' directory and export a React component as default. What does Next.js do with this component?
AIt treats the component as a server component and renders it on the server by default
BIt ignores the component unless you wrap it in a special Next.js function
CIt automatically converts the component into a class component
DIt requires you to manually register the component in a routing file
Attempts:
2 left
💡 Hint
Next.js 14 uses server components by default in the app directory.
❓ lifecycle
advanced
2:00remaining
How does Next.js handle data fetching in server components?
Consider a server component in Next.js that fetches data using 'fetch' inside the component body. When and where does this data fetching happen?
AData fetching happens both on server and client simultaneously
BData fetching happens on the client after the page loads
CData fetching is not allowed inside server components
DData fetching happens on the server during rendering before sending HTML to the client
Attempts:
2 left
💡 Hint
Server components run on the server, so their code executes there.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly defines a server action in Next.js 14?
Next.js 14 introduces server actions to handle server-side logic. Which of the following snippets correctly defines a server action?
Aconst addItem = (item) => { 'use server'; /* logic here */ }
Bexport async function addItem(item) { 'use server'; /* logic here */ }
Cexport async function addItem(item) { /* logic here */ }
Dexport const addItem = async (item) => { 'use server'; /* logic here */ }
Attempts:
2 left
💡 Hint
Server actions require the 'use server' directive at the top of the function body.
🔧 Debug
expert
3:00remaining
Why does this Next.js server component throw an error?
Given this Next.js server component code, why does it throw an error when rendering? ```jsx export default function Page() { const [count, setCount] = React.useState(0); return ; } ```
NextJS
export default function Page() {
  const [count, setCount] = React.useState(0);
  return <button onClick={() => setCount(count + 1)}>{count}</button>;
}
AThe onClick handler syntax is invalid in server components
BThe code is missing an import for React, causing a ReferenceError
CReact.useState cannot be used in server components because they run on the server and have no state
DThe button element cannot be used inside server components
Attempts:
2 left
💡 Hint
Server components do not support React state hooks like useState.

Practice

(1/5)
1. What is Next.js primarily used for?
easy
A. Writing backend server code without frontend
B. Creating mobile apps with native device access
C. Designing databases for web applications
D. Building React-based websites with routing and performance features

Solution

  1. Step 1: Understand Next.js purpose

    Next.js is a framework built on top of React to simplify building websites.
  2. Step 2: Identify key features

    It adds routing, faster loading, and SEO support to React apps.
  3. Final Answer:

    Building React-based websites with routing and performance features -> Option D
  4. Quick Check:

    Next.js = React websites + routing + speed [OK]
Hint: Next.js helps build React websites easily [OK]
Common Mistakes:
  • Confusing Next.js with mobile app frameworks
  • Thinking Next.js is only backend
  • Assuming Next.js is a database tool
2. Which of the following is the correct way to create a page in Next.js?
easy
A. Write HTML files in the public folder
B. Add routes manually in a routing config file
C. Create a React component inside the pages folder
D. Use index.html in the root directory

Solution

  1. Step 1: Recall Next.js page creation method

    Next.js uses the pages folder where each file is a React component representing a page.
  2. Step 2: Compare options

    Only Create a React component inside the pages folder matches this pattern; others describe static or manual routing methods not used in Next.js.
  3. Final Answer:

    Create a React component inside the pages folder -> Option C
  4. Quick Check:

    Next.js pages = React components in pages folder [OK]
Hint: Pages are React components in the pages folder [OK]
Common Mistakes:
  • Thinking HTML files in public folder create pages
  • Believing manual routing config is needed
  • Using index.html instead of React components
3. What will Next.js do when you create a file about.js inside the pages folder?
medium
A. Serve the page at URL /about automatically
B. Require manual route setup to access /about
C. Ignore the file unless imported elsewhere
D. Throw an error because pages must be in src folder

Solution

  1. Step 1: Understand Next.js file-based routing

    Next.js automatically maps files in pages folder to URLs matching the filename.
  2. Step 2: Apply to about.js

    The file about.js becomes accessible at /about without extra setup.
  3. Final Answer:

    Serve the page at URL /about automatically -> Option A
  4. Quick Check:

    File in pages = URL path [OK]
Hint: File name in pages = URL path automatically [OK]
Common Mistakes:
  • Thinking manual routing is needed
  • Assuming files outside src are required
  • Believing files are ignored if not imported
4. You wrote a React component in pages/contact.js but visiting /contact shows a 404 error. What is the likely mistake?
medium
A. The file is placed inside public folder
B. The component is not exported as default
C. Next.js requires manual route registration
D. The file name must be Contact.jsx with uppercase

Solution

  1. Step 1: Check Next.js page export rules

    Each page component must be the default export from its file to be recognized.
  2. Step 2: Analyze error cause

    If the component is not exported as default, Next.js won't load it, causing 404.
  3. Final Answer:

    The component is not exported as default -> Option B
  4. Quick Check:

    Pages need default export [OK]
Hint: Always export page component as default [OK]
Common Mistakes:
  • Placing pages in public folder instead of pages
  • Thinking manual route setup is needed
  • Using uppercase file names incorrectly
5. You want to improve SEO and loading speed of your React website. How does Next.js help achieve this?
hard
A. By pre-rendering pages on the server and generating static HTML
B. By running React code only on the client side after page load
C. By disabling JavaScript to speed up loading
D. By converting React components into plain HTML files manually

Solution

  1. Step 1: Understand Next.js rendering methods

    Next.js pre-renders pages either at build time or on the server, creating static or server-rendered HTML.
  2. Step 2: Connect to SEO and speed benefits

    Pre-rendered HTML loads faster and is better for search engines than client-only React apps.
  3. Final Answer:

    By pre-rendering pages on the server and generating static HTML -> Option A
  4. Quick Check:

    Next.js pre-renders for SEO and speed [OK]
Hint: Next.js pre-renders pages for SEO and speed [OK]
Common Mistakes:
  • Thinking React runs only on client in Next.js
  • Believing JavaScript must be disabled
  • Assuming manual HTML conversion is needed
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard