JS Guide
HomeQuestionsSearchResources
Search

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

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsnextjs
Next
nextjs
junior
basics

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

nextjs
react
framework
ssr
ssg
routing
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 - 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

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 structure
// 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'));

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?