"use server"
Edit this page"use server"
will enable actions in the server environment only (i.e. console logging, etc.).
Basic usage
When using "use server"
, regardless of whether rendering is happening on the server or in the browser, the functions it apply to will only run on the server.
To do this, compilation is used to transform the "use server"
function into an RPC call to the server.
If "use server"
is inserted as the first line in a file, the entire file will become server-only.
However, if "use server"
is inserted as the first line of a function, only that function will be server-only:
In both of these examples, the logHello
function, it would only show in the server console regardless of whether rendering was on the server or in the browser
Serialization
Server functions allow the serialization of many different data types in the response, using the Seroval serializer. The full list is available in Seroval's source code.
Meta information
To get a stable function-specific identifier, even for parallel processes or multiple cpu cores or workers, use the getServerFunctionMeta