Server Functions
Call server-side logic directly from components with RPC-like functions. Dinou uniquely allows Server Functions to return rendered Components, not just JSON data.
Server Functions ("use server")
Define functions with the "use server" directive to execute server-side logic directly from your components. Unlike traditional RPC, these functions can return fully rendered React Components.
// src/server-functions/get-post.jsx
"use server";
import db from "./db";
import Post from "@/components/post.jsx";
export async function getPost(postId) {
const data = await db.query("SELECT * FROM posts WHERE id = ?", [postId]);
// 🪄 Returns a rendered Component, not just JSON
return <Post post={data} />;
}Component Returns
Server Functions can return both Server and Client Components, enabling powerful rendering patterns.
Direct Database Access
Access databases, APIs, and sensitive logic securely on the server without exposing it to the client.
Server-Side Execution Guarantee
Server Functions always execute on the server, even when called from Client Components. This keeps sensitive logic and database credentials secure.
