ရိုးရိုးလေး ရှင်းပြမယ်
ရိုးရိုးလေး ရှင်းရရင်
Part 1 ရဲ့ Link Stash က ပြရုံပဲ ပြနိုင်ပါတယ်။ ဒီ Part မှာ user က form ဖြည့်ပြီး bookmark အသစ်ထည့်တာ၊ card တစ်ခုကို ဖျက်တာ၊ #docs လို tag ကို နှိပ်ပြီး filter လုပ်တာတွေကို ထည့်ပါမယ်။
စားသောက်ဆိုင်က order စာရွက်နဲ့ တူပါတယ်။ စားပွဲထိုး (form) က စာရွက်ကို မီးဖိုချောင် (Server Action) ဆီ ယူသွားပြီး မီးဖိုချောင်က စတိုခန်း (lib/db.ts) ကို ပြင်ပါတယ်။ ပြီးရင် "menu board ကို ပြန်ရေး" (revalidatePath) လို့ အော်လိုက်တော့ ဆိုင်ထဲက လူတိုင်း အသစ်ကို မြင်ရပါတယ်။ Order တွေက browser ထဲမှာ မဟုတ်ဘဲ server ပေါ်မှာ ဖြစ်တာပါ။
Problem → Why → Solution
ပြဿနာ: browser ထဲမှာပဲ ရှိနေတဲ့ bookmark
React lesson တွေကနေ ရင်းနှီးတဲ့ နည်းနဲ့ home page ကို "use client" ပြောင်း၊ useState ထဲ array ထည့်ပြီး button နှိပ်ရင် push လုပ်ကြည့်ပါတယ်။ ပထမတော့ အလုပ်လုပ်သလို ထင်ရပါတယ်။
ဒါပေမယ့် page ကို refresh လုပ်လိုက်တာနဲ့ အသစ်ထည့်ထားတဲ့ bookmark ပျောက်သွားပါတယ်။ ဖုန်းကနေ ဖွင့်ကြည့်ရင်လည်း မမြင်ရပါဘူး။ ဘာလို့လဲဆိုတော့ data က browser tab တစ်ခုရဲ့ memory ထဲမှာပဲ ရှိနေလို့ပါ။ JavaScript မ load ရသေးခင် နှိပ်လိုက်ရင် button က ဘာမှလည်း မလုပ်ပါဘူး။
"use client";
import { useState } from "react";
export default function HomePage() {
const [items, setItems] = useState([{ id: "1", title: "Next.js Docs" }]);
const add = () => setItems([...items, { id: "2", title: "React Docs" }]);
// Lives only in this tab: refresh, another device, or no JS = nothing saved
return <button onClick={add}>Add ({items.length})</button>;
}ဘာကြောင့် server ကို ရောက်ရမှာလဲ
User အားလုံး မြင်ရမယ့် data ကို server က ပိုင်ရပါတယ်။ Client state က "ဒီ tab မှာ ဘာဖွင့်ထားလဲ" လို ယာယီ UI အခြေအနေအတွက်ပါ။ Server Action ဆိုတာ form submit ကို server function တစ်ခုဆီ တိုက်ရိုက် ပို့ပေးတဲ့ နည်းဖြစ်လို့ API route သီးသန့် မရေးဘဲ server data ကို ပြင်လို့ ရပါတယ်။
Core concept: form → Server Action → store → revalidate
Part 1 မှာ page တွေက lib/db.ts ကိုပဲ ခေါ်အောင် လုပ်ထားခဲ့လို့ အခု lib/db.ts ရဲ့ အတွင်းပိုင်းကိုပဲ ပြင်ပါမယ်။ Seed data ကို copy ကူးပြီး let array ထဲ ထည့်၊ getBookmarks(tag?)၊ addBookmark()၊ deleteBookmark() ကို ထည့်ပါတယ်။ Database မဟုတ်သေးလို့ server restart လုပ်တိုင်း seed data သုံးခုကို ပြန်ရောက်ပါမယ်။ ပြီးရင် bookmark အသစ်တစ်ခု ထည့်တဲ့ ခရီးစဉ်က ဒီလိုပါ။
၁။ "use server" file
app/actions.ts ရဲ့ ပထမဆုံး statement က "use server" ပါ။ ဒီ file က export လုပ်တဲ့ async function တိုင်းကို Next.js က browser ကနေ ခေါ်လို့ရတဲ့ Server Action အဖြစ် သတ်မှတ်ပါတယ်။ Function code ကတော့ server ပေါ်မှာပဲ ရှိနေပါတယ်။
၂။ <form action={createBookmark}>
Submit နှိပ်တဲ့အခါ browser က input value တွေကို POST request အဖြစ် ပို့ပြီး action က FormData object ကို ရပါတယ်။ Server Component ထဲက form ဖြစ်လို့ JavaScript မ load ရသေးခင်တောင် အလုပ်လုပ်ပါတယ်။ ဒါကို progressive enhancement လို့ ခေါ်ပါတယ်။
၃။ ဖတ်၊ စစ်၊ သိမ်း
formData.get("title") က string ဒါမှမဟုတ် File ဒါမှမဟုတ် null ကို ပြန်ပေးလို့ String(... ?? "") နဲ့ string အဖြစ် ပြောင်းပြီး trim လုပ်ပါတယ်။ Server Action ကို ဘယ်သူမဆို ခေါ်လို့ရလို့ browser ရဲ့ required attribute ကို မယုံဘဲ server မှာ ပြန်စစ်ပါ။ ပြီးမှ addBookmark() ကို ခေါ်ပါတယ်။
၄။ revalidatePath("/") နဲ့ redirect("/")
revalidatePath("/") က "/" page ရဲ့ cache လုပ်ထားတဲ့ ရလဒ်ကို အဟောင်းလို့ မှတ်ပြီး action ကနေ ခေါ်တဲ့အခါ UI ကို ချက်ချင်း update လုပ်ပေးပါတယ်။ redirect("/") က user ကို list ဆီ ပြန်ပို့ပါတယ်။
One submit, end to end
----------------------
browser server
------- ------
<form action={createBookmark}>
| POST (FormData)
+-----------------------> createBookmark(formData)
read + trim + check
addBookmark() -> lib/db.ts array
revalidatePath("/")
redirect("/")
<-----------------------+ fresh "/" with the new card
list shows 4 bookmarks"use server";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { addBookmark, deleteBookmark } from "@/lib/db";
export async function createBookmark(formData: FormData) {
const title = String(formData.get("title") ?? "").trim();
const url = String(formData.get("url") ?? "").trim();
const tags = String(formData.get("tags") ?? "")
.split(",")
.map((t) => t.trim())
.filter(Boolean);
if (!title || !url) return; // Part 3 shows these errors in the form
addBookmark({ title, url, tags });
revalidatePath("/");
redirect("/");
}
export async function removeBookmark(id: string) {
deleteBookmark(id);
revalidatePath("/");
}Action နှစ်ခုလုံးကို app/actions.ts file တစ်ခုတည်းမှာ ထားတာ သတိထားပါ။ Form page နဲ့ home page နှစ်ခုလုံးက ဒီ file ကနေ import လုပ်ပြီး Part 3 မှာ Client Component ကနေလည်း ဒီ action ကိုပဲ ပြန်သုံးပါမယ်။ removeBookmark က formData မယူဘဲ id ကိုပဲ ယူပါတယ်။ အဲဒီ id ကို ဘယ်လို ပို့လဲဆိုတာ အောက်က deeper section မှာ ကြည့်ပါမယ်။
- Form က FormData ကို server ဆီ ပို့
- Action က ဖတ်၊ စစ်ပြီး store ကို ပြင်
- revalidatePath က page ကို အဟောင်းလို့ မှတ်
- Page က store ကနေ အသစ် render
Server ပေါ်က data ကို ပြင်တဲ့ code တိုင်းက "ဘယ် page တွေ အဟောင်းဖြစ်သွားလဲ" ကိုပါ ပြောပေးရပါတယ်။
အခြေခံ ပုံစံ: Server Action နဲ့ form
// app/actions.ts
"use server";
export async function saveThing(formData: FormData) {
const name = String(formData.get("name") ?? "").trim();
if (!name) return;
await store.add(name);
revalidatePath("/things");
}
// any Server Component
<form action={saveThing}><input name="name" /><button>Save</button></form>Input ရဲ့ name attribute က formData.get() ထဲက key ဖြစ်ပါတယ်။ Data ပြောင်းပြီးရင် အဲဒီ data ကို ပြတဲ့ path ကို revalidate လုပ်ပါ။
Store ကို framework မပါဘဲ စမ်းကြည့်မယ်
lib/db.ts က Next.js ကို import မလုပ်လို့ Node မှာ တိုက်ရိုက် run လို့ ရပါတယ်။ အောက်က file မှာ store နဲ့အတူ action လုပ်မယ့်အတိုင်း FormData အစစ်ကို ဖတ်တဲ့ အပိုင်းကိုပါ simulate လုပ်ထားပါတယ်။ Project ထဲမှာတော့ type နဲ့ seed ကို lib/bookmarks.ts ကနေ import လုပ်ပြီး function တွေကို export လုပ်ပါ။
// lib/db.ts - an in-memory store (Part 1's type and seed data are inlined
// here so the file runs on its own)
type Bookmark = { id: string; title: string; url: string; tags: string[] };
type NewBookmark = Omit<Bookmark, "id">;
const seedBookmarks: Bookmark[] = [
{ id: "1", title: "Next.js Docs", url: "https://nextjs.org/docs",
tags: ["docs", "nextjs"] },
{ id: "2", title: "MDN Web Docs", url: "https://developer.mozilla.org",
tags: ["docs"] },
{ id: "3", title: "Can I use", url: "https://caniuse.com", tags: ["reference"] },
];
let bookmarks: Bookmark[] = [...seedBookmarks];
let nextId = seedBookmarks.length + 1;
function getBookmarks(tag?: string): Bookmark[] {
if (!tag) return bookmarks;
return bookmarks.filter((b) => b.tags.includes(tag));
}
function addBookmark(data: NewBookmark): Bookmark {
const bookmark: Bookmark = { id: String(nextId++), ...data };
bookmarks = [bookmark, ...bookmarks]; // newest first
return bookmark;
}
function deleteBookmark(id: string): boolean {
const before = bookmarks.length;
bookmarks = bookmarks.filter((b) => b.id !== id);
return bookmarks.length < before;
}
// --- what the Server Actions will do, simulated with a real FormData ---
const show = (list: Bookmark[]) =>
list.map((b) => `${b.id}:${b.title}`).join(" | ") || "(none)";
const form = new FormData();
form.set("title", " React Docs ");
form.set("url", "https://react.dev");
form.set("tags", "docs, react,");
const tags = String(form.get("tags") ?? "")
.split(",")
.map((t) => t.trim())
.filter(Boolean);
const added = addBookmark({
title: String(form.get("title") ?? "").trim(),
url: String(form.get("url") ?? "").trim(),
tags,
});
console.log("added:", added.id, JSON.stringify(added.tags));
console.log("all:", show(getBookmarks()));
console.log("?tag=docs:", show(getBookmarks("docs")));
console.log("?tag=Docs:", show(getBookmarks("Docs")));
console.log("delete 2:", deleteBookmark("2"));
console.log("delete 2 again:", deleteBookmark("2"));
console.log("seed untouched:", seedBookmarks.length);Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- A copy, not the seed itself
let bookmarks: Bookmark[] = [...seedBookmarks];Spread နဲ့ array အသစ်ဖန်တီးလို့ add/delete တွေက seedBookmarks ကို မထိပါဘူး။ Output နောက်ဆုံးလိုင်းမှာ seed က 3 ခု ဆက်ရှိနေတာ မြင်ရပါတယ်။
- Deterministic ids
const bookmark: Bookmark = { id: String(nextId++), ...data };Counter ကို String() နဲ့ ပြောင်းပြီး Part 1 လို string id ကို ဆက်ထားပါတယ်။ Database အစစ်မှာတော့ database ကပဲ id ထုတ်ပေးလေ့ရှိပါတယ်။
- Replace, do not mutate
bookmarks = [bookmark, ...bookmarks]; // newest firstArray အသစ်နဲ့ အစားထိုးလို့ အသစ်က ထိပ်ဆုံးမှာ ရောက်ပါတယ်။ "all:" လိုင်းမှာ 4:React Docs က ရှေ့ဆုံး ဖြစ်နေတာ ဒါကြောင့်ပါ။
- Delete reports what happened
return bookmarks.length < before;ပထမအကြိမ် delete က true၊ ဒုတိယအကြိမ်က ဖျက်စရာ မရှိတော့လို့ false ပါ။ Double-click နဲ့ နှစ်ခါ submit ဖြစ်တာကို ဒီ return value နဲ့ သိနိုင်ပါတယ်။
- Tags are compared exactly
return bookmarks.filter((b) => b.tags.includes(tag));includes() က စာလုံးအကြီးအသေး ခွဲလို့ ?tag=Docs က ဘာမှ မတွေ့ပါဘူး။ Challenge မှာ tag တွေကို သိမ်းခါနီး lowercase ပြောင်းပြီး ဒီပြဿနာကို ဖြေရှင်းပါမယ်။
added: 4 ["docs","react"]
all: 4:React Docs | 1:Next.js Docs | 2:MDN Web Docs | 3:Can I use
?tag=docs: 4:React Docs | 1:Next.js Docs | 2:MDN Web Docs
?tag=Docs: (none)
delete 2: true
delete 2 again: false
seed untouched: 3Form page၊ delete button နဲ့ tag filter
app/bookmarks/new/page.tsx ကို ဖန်တီးလိုက်တာနဲ့ Part 1 မှာ [id] က ဖမ်းနေခဲ့တဲ့ /bookmarks/new က form page ကို ရောက်လာပါတယ်။ Home page မှာတော့ searchParams prop ကို await လုပ်ပြီး tag ကို ဖတ်ပါတယ်။ ?tag=docs&tag=react လို key တူနှစ်ခါ ပါလာရင် တန်ဖိုးက array ဖြစ်လာလို့ type ကို string | string[] လို့ ရေးပြီး string ဖြစ်မှသာ filter လုပ်ပါတယ်။
Delete button မှာ id လိုပါတယ်။ removeBookmark.bind(null, b.id) က id ကို ပထမ argument အဖြစ် ကြိုထည့်ထားတဲ့ function အသစ်ကို ပြန်ပေးပါတယ်။ Hidden input သုံးတာထက် ဒီနည်းက id ကို HTML ထဲမှာ value အဖြစ် မထည့်ရဘဲ JavaScript မပါလည်း အလုပ်လုပ်ပါတယ်။
// app/bookmarks/new/page.tsx
import { createBookmark } from "@/app/actions";
export default function NewBookmarkPage() {
return (
<form action={createBookmark} className="bookmark-form">
<label htmlFor="title">Title</label>
<input id="title" name="title" required />
<label htmlFor="url">URL</label>
<input id="url" name="url" type="url" required placeholder="https://" />
<label htmlFor="tags">Tags (comma separated)</label>
<input id="tags" name="tags" placeholder="docs, react" />
<button type="submit">Save bookmark</button>
</form>
);
}
// app/page.tsx - "/" and "/?tag=docs"
import Link from "next/link";
import { getBookmarks } from "@/lib/db";
import { removeBookmark } from "@/app/actions";
type Props = { searchParams: Promise<{ tag?: string | string[] }> };
export default async function HomePage({ searchParams }: Props) {
const { tag } = await searchParams;
const activeTag = typeof tag === "string" ? tag : undefined;
const bookmarks = getBookmarks(activeTag);
return (
<section>
{activeTag && <p>Tag: {activeTag} <Link href="/">clear</Link></p>}
<ul className="bookmark-list">
{bookmarks.map((b) => (
<li key={b.id} className="card">
<Link href={`/bookmarks/${b.id}`}>{b.title}</Link>
{b.tags.map((t) => (
<Link key={t} href={`/?tag=${encodeURIComponent(t)}`}>#{t}</Link>
))}
<form action={removeBookmark.bind(null, b.id)}>
<button type="submit">Delete</button>
</form>
</li>
))}
</ul>
{bookmarks.length === 0 && <p>No bookmarks here yet.</p>}
</section>
);
}In-memory store ရဲ့ ကန့်သတ်ချက်
Module-level array က server process တစ်ခုရဲ့ memory ထဲမှာပဲ ရှိပါတယ်။ Server restart လုပ်ရင် ပျောက်ပြီး dev မှာ file ပြင်လို့ module ပြန် load ဖြစ်ရင်လည်း seed ကို ပြန်ရောက်နိုင်ပါတယ်။ Serverless hosting မှာ instance တစ်ခုစီက ကိုယ်ပိုင် copy ရှိပါတယ်။ Learning project အတွက် အဆင်ပြေပေမယ့် user data အစစ်အတွက် database-layer lesson က database ကို သုံးပါ။
လက်တွေ့ project တွေမှာ
လက်တွေ့ project တွေမှာ
Admin panel တွေ၊ comment form တွေ၊ todo app တွေမှာ "form → server function → database → page refresh" ဆိုတဲ့ ပုံစံကို နေ့တိုင်းလိုလို ရေးရပါတယ်။ Server Action မပေါ်ခင်က API route တစ်ခု၊ client မှာ fetch code၊ loading state စတာတွေ ရေးရပါတယ်။ အခုတော့ simple mutation အများစုကို action function တစ်ခုနဲ့ ပြီးနိုင်ပါတယ်။
Filter ကို ?tag=docs လို URL ထဲမှာ ထားတာကလည်း online shop တွေရဲ့ category filter၊ search result page တွေမှာ အမြဲတွေ့ရတဲ့ ပုံစံပါ။ URL ကို copy ကူးပြီး သူငယ်ချင်းကို ပို့ရင် filter လုပ်ထားတဲ့ အတိုင်း မြင်ရပါတယ်။ Back button လည်း မှန်မှန် အလုပ်လုပ်ပြီး bookmark လုပ်ထားလို့လည်း ရပါတယ်။ ဒါကို useState ထဲမှာ ထားခဲ့ရင် ဒီအကျိုးကျေးဇူးတွေ မရတော့သလို filter လုပ်ထားတဲ့ page တွေကို search engine တွေကလည်း index မလုပ်နိုင်တော့ပါဘူး။
အမှားများ
ဖြစ်လေ့ရှိတဲ့ အမှားများ
"use server" ကို မေ့တာ
Directive မပါရင် createBookmark က ရိုးရိုး function ပဲ ဖြစ်ပါတယ်။ Function တစ်ခုကို browser ဆီ ပို့လို့ မရလို့ form render လုပ်တဲ့အခါ error တက်ပါတယ်။ Client Component ကနေ import လုပ်ရင်တော့ server code က client bundle ထဲ ရောက်သွားနိုင်ပါတယ်။ File ရဲ့ ပထမဆုံး statement အဖြစ် "use server" ထည့်ပါ။
revalidatePath ကို မခေါ်တာ
Store ထဲမှာ bookmark ရောက်သွားပေမယ့် user က list အဟောင်းကို ဆက်မြင်နေနိုင်ပြီး manual refresh လုပ်မှ ပေါ်ပါတယ်။ Data ပြောင်းတဲ့ action တိုင်းမှာ အဲဒီ data ကို ပြတဲ့ path ကို revalidate လုပ်ပါ။
redirect ကို try/catch ထဲ ထည့်တာ
redirect() က special error တစ်ခု throw လုပ်ပြီး အလုပ်လုပ်ပါတယ်။ try { ... redirect("/") } catch {} လို့ ရေးရင် catch က အဲဒါကို ဖမ်းစားလိုက်လို့ redirect မဖြစ်တော့ပါဘူး။ redirect ကို try block အပြင်၊ အလုပ်အားလုံးပြီးမှ ခေါ်ပါ။
Browser validation ကိုပဲ ယုံတာ
Server Action က public POST endpoint တစ်ခုပါ။ curl နဲ့ required၊ type="url" ကို ကျော်ပြီး javascript: URL လို အန္တရာယ်ရှိတဲ့ value ပို့လို့ ရပါတယ်။ Challenge မှာ server ဘက်က validation ကို ရေးပါမယ်။
Mini challenge
lib/validation.ts ကို ရေးပါ
createBookmark action ထဲက input ဖတ်တဲ့ logic ကို test လုပ်လို့ရတဲ့ pure function တွေအဖြစ် ခွဲထုတ်ပါ။ Tag တွေကို သန့်ရှင်းအောင် လုပ်ပြီး http/https URL ကိုပဲ လက်ခံပါ။ ပြီးရင် action က readBookmarkForm() ကို ခေါ်ပြီး ok မဟုတ်ရင် return ပြန်ရုံပါပဲ။
- parseTags(raw): comma နဲ့ ခွဲ၊ trim၊ lowercase၊ အလွတ်ဖယ်၊ ထပ်နေတာဖယ်ပြီး 5 ခုထက် မပိုစေနဲ့
- normalizeUrl(raw): URL မဟုတ်ရင် ဒါမှမဟုတ် http:/https: မဟုတ်ရင် null၊ မှန်ရင် url.href
- readBookmarkForm(formData): { ok: true, data } ဒါမှမဟုတ် { ok: false, error } ကို ပြန်ပေးပါ
- javascript:alert(1) နဲ့ "nextjs.org" (scheme မပါ) နှစ်ခုလုံးကို ငြင်းပါ
type NewBookmark = { title: string; url: string; tags: string[] };
type ReadResult = { ok: true; data: NewBookmark } | { ok: false; error: string };
function parseTags(raw: string): string[] {
// TODO: split, trim, lowercase, drop empty strings
// TODO: remove duplicates (a Set keeps first-seen order), keep at most 5
}
function normalizeUrl(raw: string): string | null {
// TODO: new URL() throws on bad input - catch it and return null
// TODO: only "http:" and "https:" protocols are allowed
}
function readBookmarkForm(formData: FormData): ReadResult {
// TODO: title is required, url must pass normalizeUrl, tags via parseTags
}
// TODO: try a few inputs, including "javascript:alert(1)" and "nextjs.org"ရလဒ်: ["docs","react","css"]၊ https://nextjs.org/docs (host ကို lowercase ပြောင်းပြီး)၊ null နှစ်ခု၊ ပြီးရင် ok:true result တစ်ခု (url က https://react.dev/ ဆိုပြီး slash ပါလာ) နဲ့ error result နှစ်ခု ထွက်ပါမယ်။
အရိပ်အမြွက် ကြည့်ရန်
[...new Set(tags)] က ပထမဆုံးတွေ့တဲ့ အစီအစဉ်အတိုင်း ထပ်နေတာတွေကို ဖယ်ပါတယ်။ new URL("nextjs.org") က scheme မပါလို့ throw လုပ်ပါတယ်။ new URL("javascript:alert(1)") ကတော့ အောင်မြင်ပေမယ့် protocol က "javascript:" ဖြစ်နေပါတယ်။
အဖြေ ကြည့်ရန်
type NewBookmark = { title: string; url: string; tags: string[] };
type ReadResult = { ok: true; data: NewBookmark } | { ok: false; error: string };
const MAX_TAGS = 5;
function parseTags(raw: string): string[] {
const tags = raw
.split(",")
.map((t) => t.trim().toLowerCase())
.filter((t) => t.length > 0);
return [...new Set(tags)].slice(0, MAX_TAGS);
}
function normalizeUrl(raw: string): string | null {
let url: URL;
try {
url = new URL(raw.trim());
} catch {
return null; // not a URL at all
}
if (url.protocol !== "http:" && url.protocol !== "https:") return null;
return url.href;
}
function readBookmarkForm(formData: FormData): ReadResult {
const title = String(formData.get("title") ?? "").trim();
if (title.length === 0) return { ok: false, error: "Title is required" };
const url = normalizeUrl(String(formData.get("url") ?? ""));
if (url === null) return { ok: false, error: "Enter an http(s) URL" };
const tags = parseTags(String(formData.get("tags") ?? ""));
return { ok: true, data: { title, url, tags } };
}
function form(entries: Record<string, string>): FormData {
const fd = new FormData();
for (const [key, value] of Object.entries(entries)) fd.set(key, value);
return fd;
}
console.log(JSON.stringify(parseTags("Docs, react , ,docs,CSS")));
console.log(normalizeUrl(" https://Nextjs.org/docs "));
console.log(normalizeUrl("nextjs.org"));
console.log(normalizeUrl("javascript:alert(1)"));
const inputs = [
{ title: " React ", url: "https://react.dev", tags: "Docs" },
{ title: "", url: "https://react.dev" },
{ title: "Old files", url: "ftp://files.example.com" },
];
for (const entries of inputs) {
console.log(JSON.stringify(readBookmarkForm(form(entries))));
}Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- Page တွေ lib/db.ts ကိုပဲ ခေါ်ထားလို့ storage ကို file တစ်ခုထဲမှာပဲ ပြောင်းလို့ ရပါတယ်
- "use server" file ထဲက async function ကို <form action> နဲ့ ချိတ်ရင် JavaScript မပါလည်း အလုပ်လုပ်ပါတယ်
- Data ပြောင်းပြီးတိုင်း revalidatePath နဲ့ ပြတဲ့ page ကို update လုပ်ပြီး redirect ကို try/catch အပြင်မှာ ခေါ်ပါ
- Filter ကို ?tag= search param ထဲ ထားရင် share၊ back button၊ bookmark အကုန် အလုပ်လုပ်ပါတယ်
- Server Action က public endpoint ဖြစ်လို့ input ကို server ဘက်မှာ ပြန်စစ်ပါ
Next.js Documentation — Next.js