"use server" action
Files at src/actions/ with a top-level "use server" directive expose each named export as a POST endpoint at /_bext/action/. The action receives a Web Request with the form body and returns a Response. This is a separate compile path from the co-located loader/action shape on pages.
Try it
Source
// src/actions/greeting.ts
"use server";
export async function greet(req: Request): Promise<Response> {
const form = await req.formData();
const name = String(form.get("name") ?? "stranger");
// ... apply state ...
return new Response(null, {
status: 303,
headers: { Location: "/examples/use-server-action?greeted=" + name },
});
}
// page.tsx
<form method="post" action="/_bext/action/greet">
<input name="name" />
<button>greet</button>
</form>