読み方のヒント
矢印ボタン(または ← → キー)でページを移動できます。
予約の一覧は、Server Components で読みます。
// src/app/admin/reservations/page.tsx
import { Suspense } from "react";
import { listReservations } from "@/lib/reservations";
import { PickUpButton } from "@/components/PickUpButton";
const ReservationRows = async () => {
const reservations = await listReservations();
return (
<tbody>
{reservations.map((r) => (
<tr key={r.id}>
<td>{r.id}</td>
<td>{r.name}</td>
<td>{r.status === "reserved" ? <PickUpButton reservationId={r.id} /> : statusText(r.status)}</td>
</tr>
))}
</tbody>
);
};
export default function AdminReservationsPage() {
return (
<table>
<thead>
<tr><th>予約番号</th><th>お名前</th><th>状態</th></tr>
</thead>
<Suspense fallback={<tbody><tr><td colSpan={3}>読み込んでいます…</td></tr></tbody>}>
<ReservationRows />
</Suspense>
</table>
);
}
| 役割 | 書く場所 |
|---|---|
| 予約を読む | Server Components(listReservations) |
| 予約を変える | Server Actions(pickUpReservation) |
| 変えたあとに読み直す | Server Actions の中の refresh() |
| 押している途中の表示 | Client Components の useTransition |
PickUpButton は、サーバーの値を書きかえて読み直すだけで、予約の一覧を state に持ちません。どの画面も、いつもサーバーの同じ値を表示します。
お気に入りかどうかは Server Components で読み、ボタンを押したら Server Actions でサーバーに記録して refresh() で読み直します。押している途中の表示は、ボタンの Client Components で useTransition を使って出します。
7 / 16