"use server" action

Files at src/actions/<name>.ts with a top-level "use server" directive expose each named export as a POST endpoint at /_bext/action/<export>. 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.

Tip
"use server" files are compiled in a separate pass and never bundled into the client. Name exports precisely: /_bext/action/<export> is the public URL, so greet and handleUpload are safer than process or run.

Try it

src/actions/greeting.tsTypeScript
// 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 — point the form's action attribute at the compiled endpoint
<form method="post" action="/_bext/action/greet">
  <input name="name" />
  <button type="submit">greet</button>
</form>