getActionLabel
type Status = "1" | "2" | "3";
export function getActionLabel(status: Status, isVip: boolean) {
if (status === "1") {
return isVip ? "Pay now (VIP)" : "Pay now";
} else if (status === "2") {
return "View receipt";
} else if (status === "3") {
return "Contact support";
}
return "Unknown";
}
isVip props 의 애매함
onSave 처럼 핸들러 네이밍
onSave vs handleSave
- onClick={onClick} 이렇게 사용한것 어떤지?
async function onSave() {
if (name.trim().length < 2) {
alert("이름은 2글자 이상이어야 합니다.");
return;
}
if (!email.includes("@")) {
alert("이메일 형식이 올바르지 않습니다.");
return;
}
setSaving(true);
try {
const res = await fetch(`/api/users/${user.id}`, {
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify({ name, email }),
});
if (!res.ok) throw new Error("SAVE_FAILED");
alert("저장 완료!");
window.location.reload();
} catch {
alert("저장 실패!");
} finally {
setSaving(false);
}
}