What Server Actions Are: Functions That Run on the Server
You'll learn: What Server Actions are and how they enable server-side logic from your components.
The Core Concept
Server Actions are async functions marked with the 'use server' directive that execute entirely on the server. Unlike regular functions in your components, these functions run on the backend—even when called from client components. They give you a direct way to perform server-side operations like database mutations, file uploads, or API calls without building a separate REST or GraphQL endpoint.
Why This Matters
Think of Server Actions as a telephone line directly to your server. You don't need to set up an API route, manage fetch calls, or handle request/response formatting. You just call the function, and React handles the rest—serializing arguments, sending them to the server, executing the logic, and returning the result.
'use server'
async function createUser(formData: FormData) {
// This runs on the server
const name = formData.get('name')
await db.users.insert({ name })
}
You can call this from a Client Component's form action, from a Server Component directly, or even pass it as a prop. React automatically creates the bridge between client and server.
Server or Client: It Doesn't Matter
The beauty is that Server Actions work from both Server Components and Client Components. When called from the client, React handles the network request transparently. When called from the server, they execute directly without any network hop.
Key Takeaway: Server Actions are async functions marked with 'use server' that run on the backend and can be invoked from anywhere in your component tree, eliminating the need for manual API routes for server-side operations.