Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →

Top Next.js Interview Questions and Answers

The Next.js interview questions asked most often, covering the App Router, Server and Client Components, rendering strategies, Server Actions and performance.

jiocoder TeamUpdated Oct 7, 20264 min readNext.js
Top Next.js Interview Questions and Answers

Next.js is now the default way many teams build React apps, so it shows up in most React and full-stack interviews. These questions focus on the App Router, which is what interviewers expect you to know today.

1. What is Next.js and why use it over plain React?#

Next.js is a React framework that adds what React alone doesn't include: file-based routing, server rendering, static generation, data fetching on the server, API endpoints, image and font optimisation, and production builds. You get better SEO, faster first loads and less setup.

2. What is the difference between the App Router and the Pages Router?#

The Pages Router (pages/) is the older system, using getServerSideProps and getStaticProps for data. The App Router (app/) is the modern system, built on React Server Components, with nested layouts, streaming, and data fetching directly inside components. New projects should use the App Router.

3. What are Server Components and Client Components?#

In the App Router, components are Server Components by default. They run only on the server, can fetch data and read secrets directly, and send no JavaScript to the browser. Client Components start with "use client" and run in the browser too. You need them for state, effects, event handlers and browser APIs.

TSX
// app/products/page.tsx (Server Component)
import AddToCart from "./AddToCart";

export default async function Page() {
  const products = await db.product.findMany();
  return products.map(p => (
    <div key={p.id}>{p.name} <AddToCart id={p.id} /></div>
  ));
}

// app/products/AddToCart.tsx (Client Component)
"use client";
import { useState } from "react";

export default function AddToCart({ id }: { id: string }) {
  const [added, setAdded] = useState(false);
  return <button onClick={() => setAdded(true)}>{added ? "Added" : "Add"}</button>;
}
Tip

Keep "use client" as low in the tree as possible. Make only the interactive part a Client Component so the rest stays on the server.

4. Explain SSR, SSG, ISR and CSR#

StrategyWhen HTML is builtGood for
SSG (static)At build timeBlogs, docs, marketing pages
ISRAt build, then regenerated in the backgroundContent that changes now and then
SSR (dynamic)On every requestPersonalised or real-time pages
CSRIn the browserHighly interactive dashboards
TSX
// Regenerate this page at most once every 60 seconds (ISR)
export const revalidate = 60;

export default async function Page() {
  const posts = await getPosts();
  return <PostList posts={posts} />;
}

5. How does routing work in the App Router?#

  • Folders define routes, and a page.tsx file makes a route public.
  • Dynamic routes: app/blog/[slug]/page.tsx matches /blog/anything.
  • Catch-all: [...slug] matches multiple segments.
  • Route groups: (marketing) organises folders without changing the URL.
  • Special files: layout.tsx, loading.tsx, error.tsx, not-found.tsx.

6. What is the difference between layout.tsx and template.tsx?#

A layout wraps its child pages and keeps its state when you navigate between them. It doesn't re-render. A template also wraps children, but creates a new instance on every navigation, so state resets and effects run again. Use a template for things like per-page enter animations.

7. How do loading.tsx and error.tsx work?#

loading.tsx wraps the route in a React Suspense boundary and shows instantly while the page's data loads, so the user sees feedback right away. error.tsx wraps the route in an error boundary, catching errors in that segment without breaking the whole app. It must be a Client Component and receives a reset function to retry.

8. What are Server Actions?#

Server Actions are async functions marked with "use server" that run on the server but can be called directly from forms or Client Components. They replace many API routes for mutations like creating or updating data.

TSX
// app/actions.ts
"use server";
import { revalidatePath } from "next/cache";

export async function createPost(formData: FormData) {
  await db.post.create({ data: { title: String(formData.get("title")) } });
  revalidatePath("/blog");
}

// In a component
<form action={createPost}>
  <input name="title" />
  <button>Save</button>
</form>
Common mistake

Treating Server Actions as private. They are public endpoints anyone can call, so always check authentication and validate input inside the action.

9. How does Next.js optimise performance?#

  • next/image: resizes, lazy-loads and serves modern formats, and prevents layout shift.
  • next/font: self-hosts fonts with no layout shift and no external requests.
  • next/link: prefetches pages in the viewport for near-instant navigation.
  • Automatic code splitting per route, plus next/dynamic for lazy-loading heavy components.
  • Streaming with Suspense, so fast parts of the page render before slow data arrives.

Key takeaways#

  • Know the App Router well: Server Components by default, "use client" only where needed.
  • Be able to explain SSG, ISR, SSR and CSR and pick the right one for a page.
  • Understand Server Actions and always secure them like API endpoints.