199 Next.js interview questions and answers
Next.js interview questions on the App Router, Server Components, Server Actions, caching and revalidation, routing, rendering strategies, middleware and performance.
Easy70 easy Next.js questions
- 1What is Next.js and how does it differ from React?
- 2What are the main features of Next.js?
- 4What is the Pages Router in Next.js?
- 6How does file-based routing work in Next.js?
- 7What is the _app.js file and what is it used for?
- 9What is the public folder in Next.js used for?
- 10How do you create a 404 page in Next.js?
- 11What is the next.config.js file?
- 12How do you set environment variables in Next.js?
- 13What is the NEXT_PUBLIC prefix used for in environment variables?
- 14How does Next.js handle CSS imports?
- 15What are CSS Modules in Next.js?
- 16How do you create dynamic routes in Next.js?
- 18What is the difference between [slug] and [...slug]?
- 20How do you use the useRouter hook?
- 21What is the difference between router.push and router.replace?
- 22How do you programmatically navigate in Next.js?
- 25What is the Link component and how does it work?
- 27What are route groups in the App Router?
- 31What is the layout.js file in the App Router?
- 32What is the page.js file in the App Router?
- 34What is the loading.js file used for?
- 36What is getStaticProps and when do you use it?
- 37What is getServerSideProps and when do you use it?
- 43How do you fetch data in Server Components (App Router)?
- 52How do you pass data from Server Components to Client Components?
- 56How do you handle loading states during data fetching?
- 62What is the difference between Server and Client Components?
- 63When should you use the 'use client' directive?
- 64Can Server Components use hooks?
- 70Can you import a Client Component inside a Server Component?
- 81How do you create an API route in Next.js (Pages Router)?
- 82What HTTP methods are supported in API routes?
- 83How do you handle different HTTP methods in a single API route?
- 84How do you create API routes in the App Router (Route Handlers)?
- 85What is the route.js file in the App Router?
- 86How do you read request body in Route Handlers?
- 87How do you return JSON from a Route Handler?
- 91How do you create dynamic API routes?
- 101What is middleware in Next.js?
- 102Where do you define middleware in Next.js?
- 104How do you redirect users in middleware?
- 106How do you access cookies in middleware?
- 114How do you protect pages using getServerSideProps?
- 118What is the useSession hook in NextAuth?
- 121What is the Next.js Image component?
- 122What are the benefits of using next/image?
- 123What is lazy loading and how does Next.js handle it?
- 124What is the priority prop in next/image?
- 125How do you configure remote image domains in Next.js?
- 126What is next/font and how does it optimize fonts?
- 129What is code splitting in Next.js?
- 130How does Next.js handle dynamic imports?
- 132What is the purpose of the next/dynamic function?
- 146How do you use Tailwind CSS in Next.js?
- 149How do you use Sass in Next.js?
- 150What is the globals.css file?
- 151How do you use CSS variables in Next.js?
- 164How does Next.js handle redirects in next.config.js?
- 165How does Next.js handle rewrites?
- 166What are headers in next.config.js?
- 168What is the next/headers module?
- 169How do you read cookies on the server in the App Router?
- 173How do you configure path aliases in Next.js?
- 176What is the difference between next build and next dev?
- 187What is the Next.js error overlay?
- 188How do you use React DevTools with Next.js?
- 191What is the Metadata API in the App Router?
- 194How do you implement a sitemap in Next.js?
- 195How do you implement a robots.txt in Next.js?
Medium106 medium Next.js questions
- 3What is the difference between CSR, SSR, SSG, and ISR?
- 5What is the App Router introduced in Next.js 13?
- 8What is the _document.js file and when should you use it?
- 17What are catch-all routes and how do you define them?
- 19What is an optional catch-all route [[...slug]]?
- 23What is shallow routing?
- 24How do you handle query parameters in Next.js?
- 26How does prefetching work with the Link component?
- 30How do you create nested layouts in the App Router?
- 33What is the template.js file and how does it differ from layout.js?
- 35What is the error.js file used for?
- 38What is getStaticPaths and when is it required?
- 40What is Incremental Static Regeneration (ISR)?
- 41How do you set a revalidation time in ISR?
- 42What is on-demand revalidation?
- 44What is the fetch API extension in Next.js?
- 45How do you cache fetch requests in Next.js?
- 46What is cache: 'no-store' used for in fetch?
- 47What is next: { revalidate } in the fetch options?
- 48How do you use React.cache in Next.js?
- 49What is the difference between static and dynamic rendering in the App Router?
- 50What makes a route dynamic in the App Router?
- 51What is the unstable_noStore function?
- 53Can Client Components fetch data directly?
- 54What is SWR and how is it used with Next.js?
- 55What is React Query and how does it integrate with Next.js?
- 57What is Suspense and how does it work in Next.js?
- 59What are Server Actions in Next.js?
- 60How do you use use server directive?
- 61What are React Server Components (RSC)?
- 65Can Client Components be async?
- 66How do you use context in the App Router?
- 68How do you pass server data as props to Client Components?
- 69What are the limitations of Server Components?
- 71Can you import a Server Component inside a Client Component?
- 73What are third-party libraries' compatibility issues with RSC?
- 74How do you handle browser-only APIs in Server Components?
- 75What is the difference between use server and use client?
- 76How do you share state between Server and Client Components?
- 77What is serialization and why does it matter when passing props?
- 78What is a Shared Component?
- 79How does React handle hydration in Next.js?
- 80What are hydration errors and how do you fix them?
- 88How do you handle cookies in Route Handlers?
- 89How do you handle headers in Route Handlers?
- 90What is the NextRequest and NextResponse API?
- 92How do you protect API routes with authentication?
- 93What is CORS and how do you configure it in Next.js?
- 94How do you handle file uploads in Next.js?
- 96What are Edge API Routes?
- 97What is the difference between Node.js and Edge runtime?
- 98How do you add middleware to API routes?
- 100How do you handle errors in API routes?
- 103What is the matcher config in middleware?
- 105How do you rewrite URLs in middleware?
- 107How do you protect routes using middleware?
- 108What is the execution order of middleware?
- 109What runtime does middleware run on?
- 110What are the limitations of Next.js middleware?
- 111How do you implement authentication in Next.js?
- 112What is NextAuth.js (Auth.js)?
- 113How do you set up session management in Next.js?
- 115How do you protect routes using middleware?
- 117How do you handle OAuth providers with NextAuth?
- 119How do you access the session in Server Components?
- 127What is automatic font optimization in Next.js?
- 128What is next/script and what are its loading strategies?
- 131What is React.lazy and how does it work with Next.js?
- 133How do you disable SSR for a component using next/dynamic?
- 134What is tree shaking and does Next.js support it?
- 135What is bundle analysis in Next.js and how do you do it?
- 136How does Next.js optimize third-party scripts?
- 137What is the Turbopack bundler in Next.js?
- 138What are the performance metrics Next.js focuses on (Core Web Vitals)?
- 143How do you opt out of caching in the App Router?
- 144What is revalidatePath and revalidateTag?
- 145How do you use cache tags in Next.js?
- 147How do you use styled-components in Next.js?
- 152What is the recommended styling approach for Server Components?
- 153How do you handle dark mode in Next.js?
- 154How do you use PostCSS in Next.js?
- 158What are Server Actions and how do they differ from API routes?
- 159How do you handle form submissions with Server Actions?
- 160What is useFormState and useFormStatus?
- 162What is the after function in Next.js?
- 163What is the forbidden and unauthorized function in Next.js 15?
- 167How do you configure internationalization (i18n) in Next.js?
- 170What is the draftMode API in Next.js?
- 171What is Preview Mode in the Pages Router?
- 174What is the output option in next.config.js (standalone, export)?
- 175How does next export work and what are its limitations?
- 177How do you deploy Next.js on Vercel vs self-hosted?
- 178How do you configure custom server in Next.js?
- 179What is edge rendering and when should you use it?
- 180How do you test Next.js applications?
- 181What is the recommended testing setup for Next.js (Jest + Testing Library)?
- 182How do you mock useRouter in tests?
- 183How do you write end-to-end tests with Playwright or Cypress for Next.js?
- 185How do you test API routes in Next.js?
- 186How do you debug a Next.js application?
- 190How do you implement SEO in Next.js?
- 192How do you generate dynamic metadata (Open Graph, Twitter cards)?
- 193What is generateStaticParams and how does it replace getStaticPaths?
- 196What are the key differences between Next.js 13, 14, and 15?
- 198What are common pitfalls when using the App Router?
- 199How does Next.js compare to Remix, Nuxt, or Astro?
Hard23 hard Next.js questions
- 28What are parallel routes in Next.js?
- 29What are intercepting routes?
- 39What is the difference between fallback: false, true, and blocking in getStaticPaths?
- 58How do you stream data with Suspense boundaries?
- 67What is the component tree boundary between server and client?
- 72What is the "children pattern" for mixing server and client components?
- 95How do you stream responses from API routes?
- 99How do you rate-limit API routes in Next.js?
- 116How do you implement JWT-based auth in Next.js?
- 120How do you implement role-based access control (RBAC) in Next.js?
- 139How do you implement caching strategies in Next.js?
- 140What is the full route cache in the App Router?
- 141What is the router cache in the App Router?
- 142What is the data cache in the App Router?
- 148What are the challenges of CSS-in-JS in the App Router?
- 155What is the order of CSS precedence in Next.js?
- 156What is the React Server Component payload (RSC payload)?
- 157How does Next.js handle partial prerendering (PPR)?
- 161How do you handle optimistic updates with Server Actions?
- 172How do you implement a monorepo with Next.js?
- 184How do you test Server Components?
- 189How do you analyze and fix slow build times in Next.js?
- 197How do you migrate from the Pages Router to the App Router?