"use client"; import { useState } from "react"; export function NewsletterForm() { const [email, setEmail] = useState(""); const [status, setStatus] = useState<"idle" | "loading" | "done" | "error">( "idle" ); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!email) return; setStatus("loading"); try { const res = await fetch("/api/newsletter", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email }), }); setStatus(res.ok ? "done" : "error"); } catch { setStatus("error"); } } if (status === "done") { return
You're on the list.
; } return (Something went wrong. Try again.
)}