0
0
NextJSframework~20 mins

What is Next.js - Practice Questions & Exercises

Choose your learning style9 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.