The "use server" directive
The "use server" directive in the Server functions guide.
The directive is the second spelling. It needs no import, and it marks plain async functions.
- File level.
"use server"as the first statement makes every export a server function. Each export must be anasyncfunction (a declaration, anasyncarrow or function expression bound to aconst, adefaultexport, or a listedexport { f as g }). Type exports are allowed; values, classes and re-exports are not. - Function level.
"use server"as the first statement of anasyncfunction. An exported function becomes a server function under its export name. A function defined elsewhere (inside a component, say) is hoisted to a module-level export named$$server_<n>in source order, so reordering such functions changes their ids.
Directive functions are always POST, take no schema and no middleware, and cannot accept forms. The server calls
them as handler(input, event); the stub sends exactly one argument, so a second parameter is the event, and
the first is whatever the client sent: validate it yourself.