Article

Next.js for Beginners: Your Gateway to Modern Web Development

6 min read
Originally published on Medium. Read, clap or comment on Medium ↗

Why Every React Developer Should Learn Next.js (And Why It’s Easier Than You Think)

If you’ve been building React applications, you’ve probably experienced the setup fatigue. Configure webpack, set up routing, figure out SEO, optimize images, decide between client-side and server-side rendering… the list goes on. What if I told you there’s a framework that handles all of this for you, while making your apps faster and your development experience smoother?

Enter Next.js — the React framework that’s taken the web development world by storm.

What Exactly Is Next.js?

Think of Next.js as React’s more organized, production-ready sibling. While React is a library for building user interfaces, Next.js is a full-fledged framework that gives you everything you need to build complete web applications.

Created by Vercel, Next.js extends React with powerful features like:

The best part? You don’t need to understand all of these concepts on day one. Next.js works great even if you just use the basics.

Your First Next.js Project (In Less Than 5 Minutes)

Let’s get hands-on. Open your terminal and run:

npx create-next-app@latest my-first-nextjs-app
cd my-first-nextjs-app
npm run dev

That’s it! You now have a fully functional Next.js application running at http://localhost:3000.

When you run the create command, you’ll be asked a few questions:

Understanding the Folder Structure

After creating your app, you’ll see a structure like this:

my-first-nextjs-app/
├── app/
│ ├── layout.js
│ ├── page.js
│ └── globals.css
├── public/
├── package.json
└── next.config.js

Let’s break down the important parts:

app/ folder: This is where your entire application lives. Each file and folder here has a specific purpose in the App Router system.

page.js: This is your homepage. Any folder with a page.js file becomes a route in your application.

layout.js: This wraps around your pages and is perfect for shared elements like navigation bars and footers.

public/: Store static files like images here. They're accessible at the root of your domain.

Building Your First Page

Let’s create a simple “About” page. Create a new folder in app/ called about, and inside it, create a page.js file:

// app/about/page.js
export default function About() {
return (
<div>
<h1>About Us</h1>
<p>Welcome to our Next.js application!</p>
</div>
);
}

That’s it! Visit http://localhost:3000/about and you'll see your new page. No router configuration needed—the folder structure IS your routing system.

The Magic of File-Based Routing

This is where Next.js shines. Want a blog post at /blog/my-first-post? Just create:

app/
└── blog/
└── my-first-post/
└── page.js

Want a dynamic route that works for ANY blog post? Use square brackets:

app/
└── blog/
└── [slug]/
└── page.js

Now you can access the slug in your component:

// app/blog/[slug]/page.js
export default function BlogPost({ params }) {
return (
<div>
<h1>Blog Post: {params.slug}</h1>
</div>
);
}

Visit /blog/hello-world or /blog/my-journey and the slug will dynamically update!

Adding Navigation

Let’s create a navigation bar that appears on every page. Update your app/layout.js:

// app/layout.js
import Link from 'next/link';
import './globals.css';
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>
<nav style={{ padding: '20px', background: '#333', color: 'white' }}>
<Link href="/" style={{ margin: '0 10px', color: 'white' }}>
Home
</Link>
<Link href="/about" style={{ margin: '0 10px', color: 'white' }}>
About
</Link>
<Link href="/blog" style={{ margin: '0 10px', color: 'white' }}>
Blog
</Link>
</nav>
<main style={{ padding: '20px' }}>
{children}
</main>
</body>
</html>
);
}

The Link component from Next.js provides client-side navigation—pages load instantly without full refreshes.

Fetching Data the Next.js Way

One of Next.js’s superpowers is making data fetching simple. Let’s fetch some posts from an API:

// app/blog/page.js
async function getPosts() {
const res = await fetch('https://jsonplaceholder.typicode.com/posts');
if (!res.ok) throw new Error('Failed to fetch posts');
return res.json();
}
export default async function Blog() {
const posts = await getPosts(); return (
<div>
<h1>Blog Posts</h1>
<ul>
{posts.slice(0, 10).map(post => (
<li key={post.id}>
<h2>{post.title}</h2>
<p>{post.body}</p>
</li>
))}
</ul>
</div>
);
}

Notice something different? This component is async! In Next.js 14's App Router, you can use async/await directly in your components. The data is fetched on the server before the page is sent to the browser—great for SEO and performance.

Styling Your Application

Next.js works with any styling solution you prefer:

CSS Modules: Scoped CSS that won’t conflict

// app/page.module.css
import styles from './page.module.css';
export default function Home() {
return <div className={styles.container}>Hello</div>;
}

Tailwind CSS: Utility-first CSS (if you selected it during setup)

export default function Home() {
return <div className="p-4 bg-blue-500 text-white">Hello</div>;
}

CSS-in-JS: Libraries like styled-components work great too!

Image Optimization Made Simple

Next.js has a built-in Image component that automatically optimizes images:

import Image from 'next/image';
export default function Home() {
return (
<Image
src="/my-photo.jpg"
alt="My photo"
width={500}
height={300}
/>
);
}

This automatically:

Deploying Your App (In 2 Minutes)

Next.js was created by Vercel, so deployment is ridiculously simple:

  1. Push your code to GitHub
  2. Go to vercel.com and sign up
  3. Click “New Project” and import your GitHub repo
  4. Click “Deploy”

That’s it! Your app is live on the internet with a custom URL. Every time you push to GitHub, Vercel automatically deploys your updates.

Common Beginner Mistakes (And How to Avoid Them)

Mistake #1: Using regular <a> tags instead of <Link>

Mistake #2: Putting images in the wrong folder

Mistake #3: Forgetting to make components async when fetching data

Mistake #4: Not understanding when code runs on the server vs. client

What Makes Next.js Special?

After building with Next.js, going back to plain React feels like working with one hand tied behind your back. Here’s why developers love it:

Performance by default: Your apps are fast without extra work.

SEO friendly: Search engines can crawl your content easily.

Great developer experience: Hot reloading, helpful error messages, and intuitive conventions.

Scales with you: Start simple, add complexity only when you need it.

Production ready: Built-in optimizations that would take weeks to implement manually.

Your Next Steps

You now know enough to start building real projects! Here’s what to explore next:

  1. Build a personal blog — Practice routing and data fetching
  2. Add authentication — Try NextAuth.js for user login
  3. Explore the Image component — Make your sites faster
  4. Learn about Server vs Client Components — Understand the App Router deeply
  5. Study API routes — Build full-stack applications

Final Thoughts

Next.js isn’t just another framework to learn — it’s quickly becoming the standard way to build React applications. Companies like Netflix, Hulu, TikTok, and Twitch use it in production.

The beauty of Next.js is that you can start simple and grow into its more advanced features. You don’t need to understand server-side rendering, static generation, or edge computing on day one. Just build components like you would in React, and Next.js handles the complexity.

The web development landscape is constantly evolving, but Next.js has proven it’s here to stay. Whether you’re building a personal blog, a startup MVP, or an enterprise application, Next.js gives you the tools to succeed.

So what are you waiting for? Open your terminal, create that Next.js app, and start building. The best way to learn is by doing, and Next.js makes that journey enjoyable.

Happy coding! 🚀


What will you build with Next.js? Share your projects and questions in the comments below!

← All articles Discuss on Medium ↗