---
title: "'use server'"
titleForTitleTag: "'use server' directive"
---
`'use server'` is for use with [using React Server Components](/reference/rsc/server-components).
`'use server'` marks server-side functions that can be called from client-side code.
---
## Reference {/*reference*/}
### `'use server'` {/*use-server*/}
Add `'use server'` at the top of an async function body to mark the function as callable by the client. We call these functions [_Server Functions_](/reference/rsc/server-functions).
```js {2}
async function addToCart(data) {
'use server';
// ...
}
```
When calling a Server Function on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the Server Function returns a value, that value will be serialized and returned to the client.
Instead of individually marking functions with `'use server'`, you can add the directive to the top of a file to mark all exports within that file as Server Functions that can be used anywhere, including imported in client code.
#### Caveats {/*caveats*/}
* `'use server'` must be at the very beginning of their function or module; above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks.
* `'use server'` can only be used in server-side files. The resulting Server Functions can be passed to Client Components through props. See supported [types for serialization](#serializable-parameters-and-return-values).
* To import a Server Functions from [client code](/reference/rsc/use-client), the directive must be used on a module level.
* Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions.
* Always treat arguments to Server Functions as untrusted input and authorize any mutations. See [security considerations](#security).
* Server Functions should be called in a [Transition](/reference/react/useTransition). Server Functions passed to [`
);
}
```
In this example `requestUsername` is a Server Function passed to a `
Last submission request returned: {state}
>
);
}
```
Note that like most Hooks, `useActionState` can only be called in [client code](/reference/rsc/use-client).
### Calling a Server Function outside of `