Directives
use server directive
Use the directive for async callable Server Functions, at function or module scope. A module-level directive marks its exported functions. Calls from clients cross a network boundary; validate arguments and authorize each protected operation. It is not a directive required for Server Components. Source: https://react.dev/reference/rsc/use-server. Documentation-reviewed illustrative draft; installed declarations and runtime not verified.
Formal Syntax & Structure
nextjs syntaxnextjs
'use server';Working Example
Example Snippetnextjs
// app/title-check/page.tsx — public, no writesimport { redirect } from 'next/navigation';import { readTitle } from '../../lib/forms';export default function Page() { async function check(data: FormData) { 'use server'; if (readTitle(data) === null) redirect('/title-check/invalid'); redirect('/title-check/valid'); } return <form action={check}> <label htmlFor="title">Book title</label> <input id="title" name="title" required maxLength={60} /> <button type="submit">Check title</button> </form>;}