Calling Server Actions from Server Components
What you'll learn: How to invoke Server Actions directly within Server Components using plain async/await syntax.
The Simplicity of Server-to-Server Calls
Since both Server Components and Server Actions run on the server, calling one from the other is refreshingly straightforward—no special APIs, no form submissions, just regular function calls. You simply import the Server Action and await it like any async function.
Think of it like calling a helper function in the same Node.js application. There's no network boundary to cross, no serialization magic needed—it's just server code calling other server code.
How It Works
// actions.ts
'use server'
export async function createPost(title: string, content: string) {
const post = await db.posts.create({ title, content })
return post.id
}
// PostList.tsx (Server Component)
import { createPost } from './actions'
export default async function PostList() {
const posts = await db.posts.findMany()
// Later in your logic, you might call:
// const newPostId = await createPost('Hello', 'World')
return <div>{/* render posts */}</div>
}
No <form> required. No action prop. Just direct invocation.
When You'd Do This
This pattern appears when you need to perform mutations or side effects during server rendering—perhaps seeding data, triggering background jobs, or executing setup logic. The Server Action executes, completes, and your component continues rendering with the result.
Unlike Client Components, where Server Actions typically respond to user interactions, Server Components can call them as part of the render logic itself.
Key Takeaway: Server Components can directly import and await Server Actions like regular async functions—no forms, no special syntax, just straightforward server-side code execution.