'use server'
The directive that marks async functions as Server Actions, callable from the client but always run on the server.
In more detail
Put it at the top of a file to make every export a Server Action, or as the first line inside one async function. It does not make a component a Server Component; that is the default already.
Example
'use server';
export async function registerUser(formData: FormData) { /* ... */ }Related terms
- Server Functions — Async functions marked with "use server" that run on the server but can be called from client components, for example as a form action.
- directive — A string written at the top of a file or function, such as 'use client', that tells React or Next.js how to treat that code.
- 'use client' — The directive that marks a module as the entry point to client code, so it and its imports are sent to the browser.
Taught in
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Server Actions: use server Directives & Mutations — Next.js 15 & Modern App Router Architecture