Next.js interview questions

25 questions from the Next.js course, each with the correct answer and an explanation. Try to answer before you open the answer.

What Next.js Adds to React

1. In the App Router, where do components run by default?

  1. In a separate mobile app
  2. Only in the browser
  3. On the server, as Server Components
  4. Nowhere until clicked
Show answer

Answer: On the server, as Server Components

Client Components are opted into with "use client".

Lesson: Next.js and the App Router

2. Which file makes a route segment publicly accessible as a page?

  1. page.tsx
  2. layout.tsx alone
  3. styles.css
  4. README.md
Show answer

Answer: page.tsx

Only page (or route) files create reachable URLs.

Lesson: Project Structure

3. What does ○ (Static) mean in the build output?

  1. It only runs in the browser
  2. It renders on every request
  3. It failed to build
  4. The route was prerendered as static content at build time
Show answer

Answer: The route was prerendered as static content at build time

Static HTML is served to every visitor.

Lesson: Rendering Strategies at a Glance

Routing, Layouts and Dynamic Segments

4. What happens to a layout when the user navigates between its child pages?

  1. It is destroyed and rebuilt
  2. It stays mounted and keeps its state
  3. The whole site reloads
  4. Its children are ignored
Show answer

Answer: It stays mounted and keeps its state

Layouts persist across navigation.

Lesson: Layouts and Pages

5. What does generateStaticParams do?

  1. Validates form input
  2. Lists the param values to prerender as static pages at build time
  3. Creates API keys
  4. Adds CSS
Show answer

Answer: Lists the param values to prerender as static pages at build time

Prerender known pages ahead of time.

Lesson: Dynamic Routes and params

6. Why call notFound() instead of rendering "not found" text with status 200?

  1. notFound() deletes the page
  2. It is faster to type
  3. 200 pages cannot have text
  4. So users and search engines get a real 404 status
Show answer

Answer: So users and search engines get a real 404 status

Status codes matter.

Lesson: Not-Found Pages and Real 404s

Server and Client Components

7. Which is allowed in a Server Component?

  1. Awaiting a database query directly
  2. useState
  3. onClick handlers
  4. Reading window.localStorage
Show answer

Answer: Awaiting a database query directly

Server Components run on the server only.

Lesson: Server Components

8. Are Client Components rendered on the server for the first page load?

  1. Only in development
  2. No, never
  3. Yes, they are prerendered to HTML and then hydrated in the browser
  4. Only if they have no state
Show answer

Answer: Yes, they are prerendered to HTML and then hydrated in the browser

"use client" means "also runs in the browser", not "only in the browser".

Lesson: Client Components

9. Which prop cannot normally be passed from a Server to a Client Component?

  1. A number array
  2. A string
  3. A regular function (other than a Server Action)
  4. A plain object
Show answer

Answer: A regular function (other than a Server Action)

Props must be serializable.

Lesson: The Server-Client Boundary

Static, Dynamic and Cached Data

10. Why did the static page show the same timestamp on every request?

  1. It was rendered once at build time and served from cache
  2. The clock was broken
  3. Static pages render in the browser
  4. curl caches responses
Show answer

Answer: It was rendered once at build time and served from cache

Static means rendered ahead of time.

Lesson: Static Versus Dynamic Rendering

11. What does ● (SSG) mean in the build output?

  1. A client-only page
  2. A failed page
  3. An API route
  4. Pages prerendered as static HTML from generateStaticParams
Show answer

Answer: Pages prerendered as static HTML from generateStaticParams

Static generation for known params.

Lesson: Prerendering Dynamic Routes

12. In the Cache Components model, how do you mark a function's result as cacheable?

  1. Name the file cache.ts
  2. Add the "use cache" directive and set a cacheLife
  3. Use useMemo
  4. Add a CSS class
Show answer

Answer: Add the "use cache" directive and set a cacheLife

Directive plus lifetime.

Lesson: Caching Models: Cache Components and the Previous Model

13. When should you call revalidatePath or revalidateTag?

  1. On every page view
  2. Right after a mutation that changes the cached data
  3. Never; caches update themselves instantly
  4. Only during the build
Show answer

Answer: Right after a mutation that changes the cached data

Invalidate caches when data changes.

Lesson: Revalidation

Mutations With Server Actions

14. What marks a function as a Server Action?

  1. Exporting it from next.config
  2. The "use client" directive
  3. Naming it action.js
  4. The "use server" directive
Show answer

Answer: The "use server" directive

Server Functions run on the server when called from the client.

Lesson: Server Actions in Forms

15. Why must Server Actions check authorisation?

  1. They can be called directly with any arguments, like public endpoints
  2. React checks permissions automatically
  3. They only run in development
  4. Forms cannot be submitted by attackers
Show answer

Answer: They can be called directly with any arguments, like public endpoints

Treat actions as public APIs.

Lesson: Securing Server Actions

16. Which hook exposes a form's pending state to a child button?

  1. useRef
  2. useEffect
  3. useFormStatus
  4. useId
Show answer

Answer: useFormStatus

Pending state comes from the parent form.

Lesson: Form UX: Pending States and Errors

Route Handlers, Proxy and Redirects

17. What does a Route Handler file export?

  1. A CSS module
  2. A React component named Page
  3. Functions named after HTTP methods, such as GET and POST
  4. A layout
Show answer

Answer: Functions named after HTTP methods, such as GET and POST

route.ts is an HTTP endpoint.

Lesson: Route Handlers

18. Should a proxy cookie check be your only authorisation?

  1. No, also check permissions where data is read and changed
  2. Yes, it is sufficient
  3. Only for GET requests
  4. Only in production
Show answer

Answer: No, also check permissions where data is read and changed

Defence in depth.

Lesson: Proxy (Formerly Middleware)

19. Which status does a permanent redirect in next.config use?

  1. 500
  2. 200
  3. 404
  4. 308
Show answer

Answer: 308

Permanent redirects preserve the method and are cached.

Lesson: Redirects and Configuration

Metadata, Loading, Errors and Assets

20. Where is generateMetadata useful?

  1. For static CSS
  2. When titles or descriptions depend on params or data, like a product name
  3. For client-side state
  4. For database migrations
Show answer

Answer: When titles or descriptions depend on params or data, like a product name

Dynamic metadata from data.

Lesson: Metadata

21. Why must error.tsx be a Client Component?

  1. Server Components cannot render text
  2. Error boundaries need client-side state and a reset handler
  3. It is only used in development
  4. It must load CSS
Show answer

Answer: Error boundaries need client-side state and a reset handler

Interactive recovery happens in the browser.

Lesson: Loading and Error States

22. Why give next/image a width and height?

  1. To disable optimisation
  2. To make the image square
  3. Because it cannot load otherwise in any case
  4. To reserve space and avoid layout shift while it loads
Show answer

Answer: To reserve space and avoid layout shift while it loads

Stable layout improves Core Web Vitals.

Lesson: Images and Fonts

Building, Deploying and Reviewing

23. Which deployment option cannot support Server Actions?

  1. A fully static export (output: "export")
  2. A Node.js server running next start
  3. A container built with output: "standalone"
  4. A platform with Next.js support
Show answer

Answer: A fully static export (output: "export")

Server features need a server runtime.

Lesson: Building and Deploying

24. What happens to a variable named NEXT_PUBLIC_API_KEY?

  1. It is encrypted automatically
  2. It stays on the server
  3. Its value is inlined into the browser bundle and visible to users
  4. It is ignored
Show answer

Answer: Its value is inlined into the browser bundle and visible to users

Only public values get the prefix.

Lesson: Environment Variables and Security

25. Which item belongs on a Next.js review checklist?

  1. Make every component a Client Component
  2. Prefix database URLs with NEXT_PUBLIC_
  3. Server Actions validate input and check permissions
  4. Return 200 for missing products
Show answer

Answer: Server Actions validate input and check permissions

Secure, deliberate, verified.

Lesson: A Next.js Review Checklist

← Back to the course