Dmytro Morar
Next.js

Server Actions

Server Actions call server functions directly from components without API routes.

Basics

  • Declare with "use server".
"use server";
  • Called via forms or direct imports.
  • Runs on the server in an isolated context.

Form handling

<form action={updateUser}>
  <input name="email" />
  <button type="submit">Save</button>
</form>
  • Data is serialized automatically.
  • No API route, no client fetch, no form state boilerplate.

Programmatic call

import { updateUser } from "./actions";
await updateUser({ name: "John" });

Advantages

  • Less client JS, simpler mutations, full server access.

Limitations

  • No browser APIs.
  • Client Components still required for interactive UI.
  • Cache config matters; mutations can make routes dynamic.

On this page