JS Guide
HomeQuestionsTopicsCompaniesResources
BookmarksSearch

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsnextjs
Next

Learn the concept

Next.js Fundamentals

nextjs
junior
basics

What is Next.js and how does it differ from React?

nextjs
react
framework
ssr
ssg
routing
app-router
Quick Answer

Next.js is a full-stack React framework that adds server-side rendering, file-based routing, and API routes on top of React, which is just a UI library for building components.

Detailed Explanation

React vs Next.js:

React is a JavaScript library for building user interfaces. It handles:

  • Component-based architecture
  • Virtual DOM and efficient updates
  • State management within components

Next.js is a framework built on top of React that adds:

  • File-based routing - No need to configure react-router
  • Server-side rendering (SSR) - Better SEO and faster initial load
  • Static site generation (SSG) - Pre-render pages at build time
  • API routes / Route Handlers - Build backend endpoints within your project
  • Image optimization - Automatic lazy loading and resizing
  • Code splitting - Automatic per-page bundles
  • Zero configuration - Works out of the box

App Router vs Pages Router:

  • The App Router (app/ directory) is the recommended approach for new projects
  • The Pages Router (pages/ directory) is the legacy system, still supported but not recommended for new apps
  • App Router supports React Server Components, nested layouts, and streaming by default

Caching in Next.js 16: Next.js 16 introduced the "use cache" directive for explicit, opt-in caching. Unlike earlier versions, fetch requests are not cached by default — you must explicitly opt in using "use cache" at the component or function level.

When to use each:

  • Use React alone for SPAs, dashboards, or when you have a separate backend
  • Use Next.js when you need SEO, SSR, or a full-stack solution

Code Examples

React app structureJSX
// React requires manual routing setup
import { BrowserRouter, Routes, Route } from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/posts/:id" element={<Post />} />
      </Routes>
    </BrowserRouter>
  );
}

// Manual code splitting
const LazyComponent = React.lazy(() => import('./HeavyComponent'));

Real-World Applications

Use Cases

Marketing Website

Build a high-performance marketing site with SSG for fast page loads, SEO-optimized metadata, and image optimization — all without configuring a separate build pipeline.

E-Commerce Storefront

Create a storefront with server-rendered product pages for SEO, dynamic cart functionality with client components, and API routes for checkout processing.

Developer Portfolio

Ship a personal portfolio with statically generated project pages, MDX blog posts, and automatic image optimization for screenshots and demos.

Mini Projects

React vs Next.js Feature Comparison

beginner

Build the same app (a blog with routing, data fetching, and images) in both plain React and Next.js. Compare bundle size, Lighthouse scores, SEO output, and developer experience side by side.

Full-Stack Todo App

beginner

Build a todo app using Next.js App Router with server components for the list, client components for interactivity, and route handlers for the REST API — demonstrating the full-stack capability in one project.

Industry Examples

Vercel

Vercel's own website and documentation are built with Next.js, showcasing SSG for docs pages, ISR for blog posts, and edge functions for dynamic content.

Netflix Jobs

Netflix uses Next.js for their jobs portal, leveraging server-side rendering for SEO and fast initial page loads across global job listings.

Resources

Next.js Documentation

docs

Next.js vs React - Key Differences

article

Related Questions

How does file-based routing work in Next.js?

junior
routing

What's the difference between SSR and SSG in Next.js?

junior
rendering
Next
How does file-based routing work in Next.js?
Next