Sub topic 3
Server Functions and Server Actions: terminology
This chapter assumes you know React components, props and hooks, and that you have read the previous chapter on what "use server" marks. It covers two names that people often mix up: Server Function and Server Action.
Why two names exist
Early documentation and many blog posts called every function marked with "use server" a Server Action. Later, React separated the two ideas:
- A Server Function is an async function that runs on the server and that client code can call.
- A Server Action is a Server Function that is used as an action. An action is a function React runs inside a transition, typically through a form's
actionprop or a call insidestartTransition.
So the name describes the function, and the second name describes how you use it. Every Server Action is a Server Function. A Server Function is only a Server Action when it is called in an action context.
| Term | Describes | Example |
|---|---|---|
| Server Function | What the function is: server-side code callable from the client | Any exported async function in a `"use server"` file |
| Server Action | How the function is used: as a form action or inside a transition | The same function passed to `<form action={...}>` |
| `"use server"` | The directive that creates Server Functions | Placed at the top of a file or the top of a function body |
One function, two roles
The function below is the same in both cases. Only the call site changes.
// app/actions.js
'use server';
import { db } from './db';
export async function createNote(formData) {
const title = String(formData.get('title') ?? '').trim();
if (title.length === 0) {
throw new Error('Title is required.');
}
await db.notes.insert({ title });
}Passing it to a form makes it a Server Action:
// app/NewNote.js
import { createNote } from './actions';
export default function NewNote() {
return (
<form action={createNote}>
<input name="title" />
<button type="submit">Add note</button>
</form>
);
}Calling it directly from a click handler makes it a plain Server Function call. Nothing wraps it in a transition, so React does not treat it as an action:
// app/QuickNote.js
'use client';
import { createNote } from './actions';
export function QuickNote() {
async function handleClick() {
const data = new FormData();
data.set('title', 'Untitled');
await createNote(data);
}
return <button onClick={handleClick}>Quick note</button>;
}If you wrapped that call in startTransition(async () => { ... }), it would be used as an action again. The function itself never changes.
Reading older material
Documentation, tutorials and framework guides written before the rename use "Server Actions" for everything. When you read them, apply this rule: if the text says "Server Action" but the function is called from a plain handler or a data-fetching helper, it means Server Function. Some frameworks still use their own wording, such as "action" for form handlers, so check what the page defines.
The error messages and APIs also keep the older word in places. For example, the useActionState hook takes an action, and it works with a Server Function because that function is being used as an action.
Using the terms in your own code
Use the narrower term when it carries information:
- Say "Server Function" when you talk about the function: where it is defined, what it accepts, how it is secured.
- Say "Server Action" when you talk about the call site: a form that submits to it, or a transition that tracks its pending state.
This keeps code review comments precise. "This Server Function lacks an ownership check" points at the function. "This Server Action does not show an error" points at the form or hook that calls it.
Exercise
A teammate says, "Our deleteNote Server Action is only called from an onClick handler with no transition, so it is not exposed to the network." Which part of this statement is wrong, and how would you describe the function correctly?
Show answer
The function is a Server Function, not a Server Action, because it is not used in an action context (no form action prop and no startTransition). The claim about exposure is also wrong: a Server Function is callable over the network whichever way your UI calls it, so it needs its own validation, authentication and authorization checks.