Skip to content

Latest commit

 

History

History
155 lines (129 loc) · 11.5 KB

File metadata and controls

155 lines (129 loc) · 11.5 KB

NextJS 15 Full Course 2025 | Become a NextJS Pro in 1.5 Hours

Disclaimer: This is a personal summary and interpretation based on a YouTube video. It is not official material and not endorsed by the original creator. All rights remain with the respective creators.

AI-Powered buttons

Teach Me: 5 Years Old | Beginner | Intermediate | Advanced | (reset auto redirect)

Learn Differently: Analogy | Storytelling | Cheatsheet | Mindmap | Flashcards | Practical Projects | Code Examples | Common Mistakes

Check Understanding: Generate Quiz | Interview Me | Refactor Challenge | Assessment Rubric | Next Steps

This document summarizes the key takeaways from the video. I highly recommend watching the full video for visual context and coding demonstrations.

Before You Get Started

  • I summarize key points to help you learn and review quickly.
  • Simply click on Ask AI links to dive into any topic you want.

Introduction to Next.js

Next.js is a React framework for building dynamic, server-rendered web apps, ideal for static blogs, complex apps, or e-commerce sites. It offers fast performance, automatic rendering, and built-in routing. The course covers setup, routing with the app router, dynamic routes, data fetching, and more.

Setting Up Your First Project

Use npx create-next-app to initialize a project. Answer prompts for TypeScript (recommended), ESLint, Tailwind CSS, app router (recommended), and TurboPack for faster builds. Skip src/ directory and keep default import alias.

  • Key Takeaway/Example: Run in an empty folder or use . for current directory; installs dependencies automatically.
  • Link for More Details: Ask AI: Setting Up Next.js Project

Understanding Project Structure

Key files include tsconfig.json for TypeScript, package.json with scripts like dev, build, start, and lint. next.config.js handles custom configs like Webpack or image optimization. Folders: public for static assets, app for core app with layout.tsx (global HTML structure) and page.tsx (root route).

Routing Basics

Next.js uses file-based routing: create folders in /app for routes, each with page.tsx exporting a component. Navigate with from next/link for client-side transitions. Global elements like navbars go in layout.tsx around {children}.

// Example: Simple navbar in layout.tsx
<div>
  <Link href="/">Home</Link>
  <Link href="/about">About</Link>
</div>
{children}
  • Key Takeaway/Example: Folder name defines route; no need for external routers.
  • Link for More Details: Ask AI: Next.js Routing

Working with Images

Use from next/image for optimizations like resizing, lazy loading, and aspect ratio stability. Place static assets in /public for easy import. For external images, add hostnames to next.config.js under images.remotePatterns.

import Image from 'next/image';

<Image src="/next.svg" alt="Next.js" width={100} height={100} />

Server and Client Components

Components default to server-side (faster load, better SEO, async data fetching). Add 'use client' at top for client components (interactivity, hooks like useState). Server components can't use hooks or browser events; fetch data directly with await fetch().

// Server component example
export default async function Page() {
  const res = await fetch('https://api.example.com/data');
  const data = await res.json();
  return <div>{data.title}</div>;
}

Data Fetching

In server components, fetch data asynchronously without useEffect. Extract to functions for reuse. Client components need useEffect or similar.

async function fetchUser(id: string) {
  const res = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`);
  return res.json();
}

Dynamic Routing

Create dynamic routes with [param] folders (e.g., /users/[userId]/page.tsx). Access params via props: await params.userId. Use notFound() from next/navigation for 404s. Customize global 404 with /app/not-found.tsx.

Handling Loading and Errors

Add loading.tsx in route folders for loading UI during fetches. Similarly, error.tsx for error boundaries.

Advanced Project Structure and Layouts

Place UI components outside /app (e.g., /components, /lib for utilities). Use nested layouts.tsx for route groups to wrap shared UI around subgroups.

Building API Routes

Create /app/api/[route]/route.ts for endpoints. Export async functions like GET, POST. Handle requests with Request object; return NextResponse.json().

import { NextResponse } from 'next/server';

export async function POST(request: Request) {
  const { name } = await request.json();
  return NextResponse.json({ message: `Hello ${name}` });
}
  • Key Takeaway/Example: Integrate backend logic; use full URL in server fetches, relative in client.
  • Link for More Details: Ask AI: API Routes in Next.js

Metadata and SEO

Export metadata object in server components/layouts for title, description, keywords. Enhances SEO via server rendering. Global in root layout; page-specific overrides.

import { Metadata } from 'next';

export const metadata: Metadata = {
  title: 'About Us',
  description: 'Learn about our company',
};
  • Key Takeaway/Example: Improves search rankings; can't use in client components.
  • Link for More Details: Ask AI: Metadata and SEO

About the summarizer

I'm Ali Sol, a Backend Developer. Learn more: