ETHIOCODE · LESSON 20 · NEXT.JS
THE REACT FRAMEWORK FOR PRODUCTION

Next.js React Framework SSR · SSG · API Routes · File-based Routing · Image Optimization

React ን Production-Ready አድርግ! SEO፣ Speed፣ API — ሁሉም አብሮ! ⬛🚀
Next.js takes React to the next level — server-side rendering, static generation, built-in API routes, and much more!

⚡ SSR
📄 SSG
🔌 API Routes
📁 File Routing
🖼️ Image Opt.
A
Created by @AppMinds_ET
01
Next.js ምንድን ነው?// React + Superpowers

Next.js = React ን top ላይ የሰራ Framework! Vercel ሰራው። Plain React ን ብቻ ሲጠቀሙ SEO ችግር ይኖራሃል — Next.js ያስተካክላሃል! ፈጣን፣ SEO-friendly፣ API routes built-in!
Next.js is a React framework by Vercel. It adds SSR, SSG, file-based routing, and API routes — making React apps production-ready!

⚛️ React (Plain)
SEO — Search engine አያያቸውም
Routing — React Router ለብቻ install
API — Backend ለብቻ ያስፈልጋል
SSR — Browser ብቻ ይሰራዋል
Image — ቀስ ሊሆን ይችላል
Client-side rendering ብቻ
+
Next
⬛ Next.js
SEO — Server ያሰራዋልና ያያሉ
File-based Routing — folder ብቻ
API Routes — /api/* built-in
SSR + SSG + ISR ሁሉ
Image component — ቀዝቃዛ fast
TypeScript — built-in support
02📁
File-based Routing// Folder = URL!

Next.js ዋናው Magic! Folder/File ስም = URL ይሆናል! React Router code አያስፈልግም — pages/about.js = yoursite.com/about ራሱ ይሆናል!
Magic! File name = URL automatically. No router setup needed — just create files in the pages folder!

📁 pages/ folder URL
📄
pages/index.js
Home page
📄
pages/about.js
About page
📁
pages/blog/index.js
Blog list
📄
pages/blog/[id].js
Dynamic route!
📁
pages/api/users.js
API endpoint!
GETyoursite.com/
GETyoursite.com/about
GETyoursite.com/blog
GETyoursite.com/blog/:id
APIyoursite.com/api/users
pages/blog/[id].js — Dynamic Route
import { useRouter } from 'next/router';

export default function BlogPost() {
  const router = useRouter();
  const { id } = router.query; // URL ውስጥ ያለ [id]

  return (
    <div>
      <h1>Blog Post #{id}</h1>
      {/* /blog/5 → id = "5" */}
      {/* /blog/hello → id = "hello" */}
    </div>
  );
}
03
Rendering Methods// SSR · SSG · ISR · CSR

Next.js 4 rendering methods አለው — ሁኔታ ሁኔታ የተለያየ ይጠቀማሉ! ምን ዓይነት ውሂብ ነው? ምን ያህል ፈጣን ያስፈልጋል? ያ ይወስናሃል!
Next.js gives you 4 ways to render pages — choose based on how often data changes and how fast you need it!

SSR
Server-Side Rendering
ሁሉም request ላይ server HTML ያሰራዋል — fresh data ሁሌ!
HTML built on every request — always fresh, slightly slower
getServerSideProps()
📄
SSG
Static Site Generation
Build ሲሆን አንድ ጊዜ ያሰራዋል — ULTRA fast! ውሂቡ አይቀያየርም።
HTML pre-built at build time — fastest possible, no server needed
getStaticProps()
🔄
ISR
Incremental Static Regen
SSG + ሰዓት ሲደርስ ራሱ ይዘምናል! Best of both worlds!
Static but auto-rebuilds every N seconds — perfect balance!
revalidate: 60
🖥️
CSR
Client-Side Rendering
Plain React ይመስላል — Browser ያሰራዋል። Dashboard ለ authenticated users!
Like regular React — runs in browser. Good for private pages
useEffect + fetch
pages/index.js — SSR vs SSG ምሳሌ
// ── SSR — ሁሉም request ላይ server ይሰራዋል ──────
export async function getServerSideProps(context) {
  const res  = await fetch(`https://api.ethiocode.com/posts`);
  const data = await res.json();

  return { props: { posts: data } };
  // ← ሁሌ fresh data ✅ | ትንሽ 느린 ⚠️
}

// ── SSG — Build time አንድ ጊዜ ብቻ ──────────────
export async function getStaticProps() {
  const res  = await fetch('https://api.ethiocode.com/courses');
  const data = await res.json();

  return {
    props: { courses: data },
    revalidate: 3600, // ISR — 1 ሰዓት ይጠብቅ ዘምን
  };
}

// ── Page Component ─────────────────────────────
export default function Home({ posts, courses }) {
  return (
    <div>
      {posts.map(p => (
        <PostCard key={p.id} post={p} />
      ))}
    </div>
  );
}
04🔌
API Routes// Backend in Next.js!

Next.js ውስጥ Backend! pages/api/ folder ውስጥ file ስትፈጥር ራሱ API endpoint ይሆናል! Express ለብቻ አያስፈልግም!
Create files in pages/api/ — each file becomes an API endpoint automatically! No separate Express server needed for simple APIs!

pages/api/users.js — Built-in API Route
// pages/api/users.js → yoursite.com/api/users
export default function handler(req, res) {

  if (req.method === 'GET') {
    // GET /api/users — ሁሉም users ስጥ
    res.status(200).json({
      users: [
        { id: 1, name: 'Abel',  role: 'admin' },
        { id: 2, name: 'Sara',  role: 'user'  },
      ]
    });
  }

  else if (req.method === 'POST') {
    // POST /api/users — አዲስ user ፍጠር
    const { name, email } = req.body;
    // DB save logic here...
    res.status(201).json({ message: 'Created!', name });
  }

  else {
    res.status(405).json({ error: 'Method not allowed' });
  }
}

// React ውስጥ ጠቅ ለማድረግ:
// fetch('/api/users') — Same domain! CORS ችግር የለም!
05🎮
Live Next.js App Demo!// Navigate Pages

ሙሉ Next.js App ምሳሌ! Home, Blog, API — File-based routing ስሜት! Page ሲቀያየር URL ይቀያየራሃል!
A real Next.js app experience — navigate between pages, test the API route, see how routing works!

🔒 ethiocode.vercel.app /
⬛ Next.js App · File: pages/index.js

EthioCode ትምህርት Platform

HTML ጀምሮ Full Stack ደረስ! ሁሉም ትምህርቶች ነፃ! React + Next.js ተጠቅሞ ሰራ!

SSR / SSG
Server-side rendering ፈጣን load
📁
File Routing
Folder = URL — ቀላሉ routing
🔌
API Routes
Backend ያስፈልጋቸዋል? pages/api/
📄 SSG Page · File: pages/blog/index.js

Blog Posts

getStaticProps() ተጠቅሞ build time ላይ ተሰራ — Ultra fast! 🚀

📄 Static Page · File: pages/about.js

About EthioCode

20+
ትምህርቶች / Lessons
1K+
አባላት / Members
Free
ሁሉም ትምህርት
@AppMinds_ET ሰርቶ @EthioCodeSoftSelect Channel ላይ አስቀምጧል። HTML ጀምሮ Full Stack ደረስ ሁሉም ነፃ ትምህርቶች!
🔌 API Route · File: pages/api/posts.js

API Route Tester

GET
← Send ቁልፍ ጫን → API response ይታያሃል
06📌
ዋና ዋና ነጥቦች// Key Takeaways
1
⬛ Next.js = React + Framework Features

React ን ታውቃለህ? Next.js ቀላሉ ነው! npx create-next-app@latest my-app — ተጀምሯል!
If you know React, you already know 80% of Next.js — it just adds superpowers on top!

2
📁 pages/ folder = Routes

pages/about.js = /about | pages/blog/[id].js = /blog/:id — React Router code ያስፈልጋቸዋል!
File system is your router. Create a file, get a route — that simple!

3
⚡ SSR vs SSG — ሁኔታ ሁኔታ ምረጥ

ዜና site → SSG (fast) | Social feed → SSR (fresh) | Dashboard → CSR (auth) | Blog → ISR (both!)
Choose rendering method based on how often data changes. ISR = best of both worlds!

4
🔌 API Routes — Full Stack in One Project

pages/api/users.js = /api/users endpoint! MongoDB + Mongoose ጨምር → ሙሉ Full Stack!
No separate Express needed for simple APIs. One Next.js project = frontend + backend!

5
🚀 Deploy → Vercel (1-click!)

GitHub push → Vercel auto-deploy! vercel.com → GitHub connect → Done! ነፃ!
Vercel made Next.js — deploying there is effortless. Push to GitHub, Vercel handles the rest!

07🎯
Quiz// ምን ተማርን?
❓ Next.js ውስጥ pages/blog.js file ስትፈጥር — URL ምን ይሆናል?
When you create pages/blog.js in Next.js — what URL does it become?
A /pages/blog — folder ስምን ጨምሮ
B /blog.js — extension ጨምሮ
C /blog — file ስም ብቻ ✅
D Router ን configure ማድረግ ያስፈልጋል
⬛ Next.js — ተጠናቀቀ!

Incredible! React Framework ትምህርት ጨረስን! 🎉

ቀጣይ ምርጫ: Docker 🐳 | GraphQL 🔮 | AWS ☁️ | Prisma 🗄️

🌐 ethiocodesoftselect.netlify.app

✈ @EthioCodeSoftSelect

ቻናሉን ክፈቱ → Join 🚀
✍️ Created by@AppMinds_ET