All questions
Showing of 95What are the main benefits of using Next.js over Create React App?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Next.js adds server rendering, a built-in router and backend code in the same project, which Create React App leaves to you. The React team has also deprecated Create React App for new apps. The main benefits are:
- Server-side rendering and static generation send finished HTML, which helps SEO.
- Routing is file-based, so a file or folder becomes a URL.
- API routes let you build backend endpoints in the same project.
- Next.js splits code automatically and produces optimized production builds with minimal configuration.
- The
Imagecomponent resizes, compresses and lazy-loads images. - Development includes hot reloading, TypeScript support and better error messages.
Create React App renders everything in the browser and has no built-in routing or data fetching.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the file-based routing system in Next.js
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Next.js uses file-based routing: it builds routes from your folder structure, so adding a page file creates a URL. In the Pages Router, every file in the pages directory becomes a route named after its path.
pages/
index.js → /
about.js → /about
contact.js → /contact
blog/
index.js → /blog
[slug].js → /blog/:slug
Each file exports a React component as the default export, and that component becomes the page for the route. Files named index map to the root of their folder, and square brackets such as [slug] create a dynamic segment that matches any value.
The App Router uses folders instead of files. Each folder under app is a URL segment, and a page.js file inside it makes that segment publicly accessible. Other files can live next to the route without becoming URLs, and special files such as layout.js add UI shared by the routes below them.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the purpose of the _app.js file?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The _app.js file holds the code that every page shares, because Next.js uses it to initialize every page. It is a custom App component that wraps all page components. You use it to:
- Keep state when navigating between pages
- Add global CSS
- Inject additional data into pages
- Handle global error boundaries
- Add common layout components
Next.js passes it the active page as Component and that page's props as pageProps. Whatever wraps Component, such as the header and footer below, appears on every page.
function MyApp({ Component, pageProps }) {
return (
<div>
<GlobalHeader />
<Component {...pageProps} />
<GlobalFooter />
</div>
);
}
export default MyApp;
_app.js belongs to the Pages Router. In the App Router, the root app/layout.js replaces both _app.js and _document.js.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you add global CSS in Next.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You add global CSS by importing a stylesheet once at the root of the app. In the Pages Router, you can import global stylesheets only in pages/_app.js, so the styles apply to every page.
// pages/_app.js
import '../styles/globals.css';
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />;
}
export default MyApp;
In the App Router, import the file in the root app/layout.js instead. The App Router lifts that restriction, so you can import global styles into any layout, page or component. Keep them for rules that apply everywhere, such as resets. Next.js does not remove a global stylesheet as you navigate between routes, so rules can conflict.
For styles that belong to one component, use CSS Modules instead. They generate unique class names, so the same class can appear in different files without clashing.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are CSS Modules and how do you use them in Next.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
CSS Modules are CSS files whose class names are scoped locally to that file. You create one by giving the file a .module.css extension, and Next.js supports them with no setup.
/* Button.module.css */
.primary {
background-color: blue;
color: white;
}
// Button.js
import styles from './Button.module.css';
function Button() {
return <button className={styles.primary}>Click me</button>;
}
Importing the file gives you an object, and styles.primary holds a generated, unique class name. Two module files can both define .primary without a naming collision, because each one gets its own class in the build.
You can import a CSS Module into any component in both the App Router and the Pages Router. Use them for component-specific styles when Tailwind utilities are not enough.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the public directory used for?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The public directory holds static files that Next.js serves from the root URL. A file at public/logo.png is available at /logo.png, with no path prefix.
public/
favicon.ico → /favicon.ico
logo.png → /logo.png
images/
hero.jpg → /images/hero.jpg
Use it for files that need a fixed URL, such as images, fonts or a site verification file. Next.js cannot safely cache files in public because they may change, so it serves them with Cache-Control: public, max-age=0.
A static file must not share its name with a page in pages, because that conflict is a build error. In the App Router, prefer the special metadata files inside app for robots.txt and the favicon.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you implement dynamic routing in Next.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You create a dynamic route by wrapping a file or folder name in square brackets. The file pages/posts/[id].js matches /posts/1, /posts/abc and any other single segment, and the matched value becomes a route parameter.
pages/
posts/
[id].js → /posts/:id
[...slug].js → /posts/* (catch-all)
// pages/posts/[id].js
import { useRouter } from 'next/router';
function Post() {
const router = useRouter();
const { id } = router.query;
return <h1>Post: {id}</h1>;
}
export default Post;
In the Pages Router you read the parameter from router.query. When the page is prerendered without server-side rendering, router.query starts as an empty object, so id is undefined until the router is ready. The [...slug].js form is a catch-all segment, which matches several segments and passes them as an array.
In the App Router, the brackets go on the folder name, as in app/posts/[id]/page.js. The page receives params as a promise, so a Server Component awaits it and a Client Component can use the useParams hook.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between Link and router.push()?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Link is a component for declarative navigation, while router.push() is a method for programmatic navigation from your code. Both perform a client-side transition without a full page reload.
Use Link for anything a user clicks to go somewhere. It extends the HTML <a> element, so it keeps normal link behavior such as opening in a new tab. It also prefetches the linked route in production when the link enters the viewport, so the route is already loaded when the user clicks.
Use router.push() when navigation is a side effect, such as after a form submits or a login succeeds. It does not prefetch on its own, so call router.prefetch() first if the next page is predictable.
import Link from 'next/link';
import { useRouter } from 'next/router';
function Navigation() {
const router = useRouter();
const handleClick = () => {
router.push('/about');
};
return (
<div>
<Link href="/about">About Page</Link>
<button onClick={handleClick}>Go to About</button>
</div>
);
}
This example imports useRouter from next/router, which belongs to the Pages Router. In the App Router, import useRouter from next/navigation inside a Client Component.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is getStaticProps and when should you use it?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
getStaticProps is a Pages Router function that fetches data at build time, so Next.js can prerender the page to static HTML. The props it returns go to the page component.
export async function getStaticProps() {
const res = await fetch('https://api.example.com/posts');
const posts = await res.json();
return {
props: {
posts,
},
revalidate: 3600, // ISR: revalidate every hour
};
}
It runs only on the server, so it can query a database directly. The revalidate field turns on Incremental Static Regeneration, which rebuilds the page in the background, here at most once an hour.
Use it when content changes rarely and is the same for every user, for better performance and SEO. It cannot read the request, so request-time data needs getServerSideProps.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is getServerSideProps and when should you use it?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
getServerSideProps is a Pages Router function that fetches data on every request at runtime and renders the page with it. The props it returns go to the page component.
export async function getServerSideProps(context) {
const { req, res, params, query } = context;
const data = await fetch(`https://api.example.com/user/${params.id}`);
const user = await data.json();
return {
props: {
user,
},
};
}
The context argument holds the request and response, the route params and the query string. On client-side navigation, Next.js calls the server to run it and gets the props back as JSON.
Use it when data changes frequently, requires authentication, or needs request-specific information. Every request waits for the server, so for data that can be cached, getStaticProps serves a prerendered page faster.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you fetch data on the client-side in Next.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You fetch data on the client with standard React patterns, either a useEffect call or a data fetching library. The page renders first, then the browser requests the data and updates the UI.
import { useState, useEffect } from 'react';
function Profile() {
const [user, setUser] = useState(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
fetch('/api/user')
.then(res => res.json())
.then(data => {
setUser(data);
setLoading(false);
});
}, []);
if (loading) return <div>Loading...</div>;
return <div>Welcome, {user.name}!</div>;
}
This works, but you write loading and error handling yourself, and nothing caches or deduplicates the requests. A library such as SWR or React Query adds caching, revalidation and request deduplication, so it is the usual choice.
Client-side fetching suits data that is user-specific or changes often, and that search engines do not need to index. It is also the only option when the data depends on browser APIs. In the App Router this code must live in a Client Component marked with 'use client'. Prefer fetching in a Server Component when the data can be rendered on the server.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you create Client Components in App Router?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You create a Client Component by adding the 'use client' directive at the top of the file, above the imports. Components in the App Router are Server Components by default, so you opt in only where you need interactivity.
'use client';
import { useState } from 'react';
function Counter() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Count: {count}
</button>
);
}
The directive declares a boundary between server and client code. Every module the file imports, and every component it renders directly, joins the client bundle, so you do not repeat the directive in child files. Client Components are still prerendered to HTML on the server, then hydrated in the browser to attach event handlers.
Use one when you need state and event handlers, effects, or browser-only APIs such as localStorage. Keep the directive on small leaf components, such as a button, rather than a whole page, so less JavaScript reaches the browser.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do loading states work in App Router?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You add a loading.js file to a route folder, and Next.js shows it instantly while that route's content loads. Next.js wraps page.js in a React Suspense boundary inside the layout, using your component as the fallback.
// app/posts/loading.js
export default function Loading() {
return <div>Loading posts...</div>;
}
// app/posts/page.js
export default async function PostsPage() {
// This delay will show the loading component
await new Promise(resolve => setTimeout(resolve, 2000));
const res = await fetch('https://api.example.com/posts');
const posts = await res.json();
return <PostsList posts={posts} />;
}
The page is an async Server Component, so the fallback stays on screen until its data resolves, then the real content streams in. The layout around it stays interactive, and navigation is interruptible. Next.js also prefetches the fallback, so a click shows it at once without waiting for the server.
loading.js covers the whole page. For finer control, wrap individual slow components in your own <Suspense> boundaries so the rest of the page renders sooner.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you create API routes in Next.js?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
You create an API route by adding a file to pages/api in the Pages Router, or a route.js file under app in the App Router. Either way the file becomes an HTTP endpoint on the server, and its code never ships to the browser.
In the Pages Router, any file inside pages/api maps to /api/*. It default-exports one handler that receives Node.js req and res objects and branches on req.method.
// pages/api/users.js
export default function handler(req, res) {
if (req.method === 'GET') {
res.status(200).json({ users: [] });
} else {
res.setHeader('Allow', ['GET']);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
In the App Router, a route.js file exports one function per HTTP method. Route Handlers use the Web Request and Response APIs, so you return a Response instead of writing to res.
// app/api/users/route.js
export async function GET() {
return Response.json({ users: [] });
}
export async function POST(request) {
const data = await request.json();
// Process data
return Response.json({ success: true });
}
A route.js file cannot sit in the same folder as a page.js, which is why APIs usually live under app/api. Both kinds are public endpoints, so validate input and check authorization in each one.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you handle different HTTP methods in API routes?
How do you access request data in API routes?
How do you optimize images in Next.js?
What is the purpose of next.config.js?
What styling options are available in Next.js?
How do you use Sass/SCSS in Next.js?
How do you implement styled-jsx in Next.js?
How do you integrate Tailwind CSS with Next.js?
How do you deploy a Next.js application to Vercel?
How do you build a Next.js application for production?
How do you configure environment variables in Next.js?
How do you create custom error pages in Next.js?
How do you set up TypeScript in Next.js?
How do you add metadata for SEO in Next.js?
What is the difference between _app.js and _document.js?
How do you pass data between pages in Next.js?
What are catch-all routes and how do you implement them?
How does prefetching work in Next.js?
What is getStaticPaths and why is it needed?
What is the difference between fallback: false, fallback: true, and fallback: 'blocking'?
What is SWR and how do you use it with Next.js?
Explain the differences between SSR, SSG, and CSR in Next.js
What is Incremental Static Regeneration (ISR)?
What are the main differences between App Router and Pages Router?
How does data fetching differ between App Router and Pages Router?
What are Server Components and how do they work in App Router?
What are layouts in App Router and how do you use them?
How do you handle errors in App Router?
How do you implement authentication in API routes?
How do you handle file uploads in API routes?
How does automatic code splitting work in Next.js?
How do you implement lazy loading in Next.js?
How do you optimize fonts in Next.js?
How do you implement redirects and rewrites in Next.js?
How do you generate a sitemap in Next.js?
How do you implement authentication with NextAuth.js?
How do you protect pages with authentication?
How do you implement CORS in Next.js API routes?
How do you implement error boundaries in Next.js?
How do you handle API errors in Next.js?
What is middleware in Next.js and how do you use it?
How do you implement internationalization (i18n) in Next.js?
How do you implement database connections in Next.js?
How do you implement search functionality in Next.js?
How do you implement custom hooks for data fetching in Next.js?
How do you type API routes in TypeScript?
How do you set up testing in Next.js?
How do you test API routes in Next.js?
How do you implement global state management in Next.js?
How do you implement data persistence in Next.js?
How do you create reusable components in Next.js?
How do you integrate a headless CMS with Next.js?
How do you implement MDX in Next.js?
What causes hydration errors in Next.js, and how do you fix them?
What is the difference between a Route Handler and a Server Action?
What is the difference between a layout and a template in the App Router?
How do you implement Progressive Web App (PWA) features in Next.js?
How do you implement Server Actions in Next.js App Router?
How do you implement hybrid rendering in Next.js?
How do you implement rate limiting in Next.js?
How do you implement real-time features with WebSockets in Next.js?
How do you implement server-side caching in Next.js?
How do you optimize Core Web Vitals in Next.js?
How do you implement A/B testing in Next.js?
How do you implement background jobs in Next.js?
How do you implement performance monitoring in Next.js?
What security considerations should you keep in mind with Next.js?
How do you set up a custom server in Next.js?
How do you implement multi-zone deployments in Next.js?
What is the Edge Runtime in Next.js, and should you still use it?
How do you analyze and optimize your Next.js bundle?
How do you implement tree shaking in Next.js?
How do you implement compound components in Next.js?
How do you integrate GraphQL with Next.js?
How do you implement render props pattern in Next.js?
How do you customize the webpack configuration in Next.js?
How do you customize the Babel configuration in Next.js?
How do you implement virtualization for large lists in Next.js?
How do you implement infinite scrolling in Next.js?
How do you implement advanced caching strategies in Next.js?
How would you migrate from the Pages Router to the App Router?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Next.js in pictures.
A quick recap of Next.js in 32 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 28 pictures come with Pro.
Next.js cheatsheet
- App Router vs Pages Router01
- Routing & navigation02
- Layouts, loading & errors03
- Server & Client Components04
- Rendering & data fetching05
- Caching & revalidation06
- API routes & Server Actions07
- Proxy, auth & security08
- Styling & performance09
- Build, test & deploy10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 28 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in81 of 95 Next.js answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.