Skip to main content

Lesson 9 of 10

Practice & Quiz - Next.js & Deployment

Capstone quiz covering Next.js App Router, RSC vs Client Components, Server Actions, ISR, SEO metadata, and Vercel deployment with a practical exercise and 5 questions.

12 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Practical Exercise - Next.js Blog with ISR & Server Actions

Practical Exercise - Next.js Blog with ISR & Server Actions
// ─── app/blog/[slug]/page.tsx ─────────────────────────────────
// Server Component (default in App Router) - no 'use client'
import { notFound } from 'next/navigation';
import type { Metadata } from 'next';

interface Post { slug: string; title: string; content: string; views: number; }

async function getPost(slug: string): Promise<Post | null> {
  const res = await fetch(`https://api.example.com/posts/${slug}`, {
    // ISR: revalidate every 60 seconds
    next: { revalidate: 60 },
  });
  if (res.status === 404) return null;
  if (!res.ok) throw new Error('Failed to fetch post');
  return res.json();
}

// Dynamic metadata - generated on the server per request
export async function generateMetadata(
  { params }: { params: { slug: string } }
): Promise<Metadata> {
  const post = await getPost(params.slug);
  if (!post) return { title: 'Post Not Found' };
  return {
    title: post.title,
    description: post.content.slice(0, 155),
    openGraph: { title: post.title, type: 'article' },
  };
}

// Static paths for top posts - rest generated on demand
export async function generateStaticParams() {
  const res = await fetch('https://api.example.com/posts?limit=10');
  const posts: Post[] = await res.json();
  return posts.map(p => ({ slug: p.slug }));
}

// ─── Server Action - runs on the server, called from client ───
async function incrementViews(slug: string) {
  'use server';
  await fetch(`https://api.example.com/posts/${slug}/views`, {
    method: 'POST',
    // Revalidate cached data after mutation
    cache: 'no-store',
  });
  // revalidatePath and revalidateTag available here
}

// ─── Client Component - interactive part only ─────────────────
'use client';
import { useOptimistic, useTransition } from 'react';

function ViewCounter({ initialViews, slug }: { initialViews: number; slug: string }) {
  const [isPending, startTransition] = useTransition();
  const [optimisticViews, addOptimisticView] = useOptimistic(
    initialViews,
    (state) => state + 1
  );

  return (
    <button
      onClick={() => startTransition(async () => {
        addOptimisticView(null); // optimistic update immediately
        await incrementViews(slug); // server action
      })}
      disabled={isPending}
    >
      👁 {optimisticViews} views
    </button>
  );
}

// ─── Page Server Component - composes server + client ─────────
export default async function BlogPost({ params }: { params: { slug: string } }) {
  const post = await getPost(params.slug);
  if (!post) notFound();

  return (
    <article>
      <h1>{post.title}</h1>
      <ViewCounter initialViews={post.views} slug={post.slug} />
      <div dangerouslySetInnerHTML={{ __html: post.content }} />
    </article>
  );
}

Capstone Quiz

Capstone Quiz
Question 1 of 5

In Next.js App Router, what is the default rendering mode for a component with no 'use client' directive?

Tip

Tip

Practice Practice Quiz Nextjs Deployment in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

Modern React: Use Hooks instead of class lifecycle methods

Practice Task

Note

Practice Task - (1) Write a working example of Practice Quiz Nextjs Deployment from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Common Mistake

Warning

A common mistake with Practice Quiz Nextjs Deployment is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react code.

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done

Final Projects

Congratulations on completing the course! Apply everything you've learned by building one of these real-world projects.

Project 1: Social Media Feed

Intermediate

Build a Twitter/Instagram-style social feed with infinite scroll and like/comment functionality.

ReactReact QueryTailwind CSS
Key features
Infinite scroll Like/comment system User profiles Responsive design
16-20 hoursGoal: A full social media frontend.

Project 2: E-Commerce Store

Advanced

Build a complete e-commerce frontend with product listings, cart, and checkout flow.

ReactRedux ToolkitReact Router
Key features
Product catalog Cart management Checkout process Order history
20-28 hoursGoal: A production-ready store frontend.

Project 3: Project Management Tool

Advanced

Create a Trello-like project management app with drag-and-drop boards.

ReactDnD KitContext API
Key features
Kanban boards Drag & drop tasks Team assignment Due dates
22-30 hoursGoal: A real-world SaaS application.