Server Components
Learn about Server Components in Dinou.
Overview
Server Components in Dinou are distinguished by the fact they are async functions. So when defining them, make them async always, whether or not they use await in their definition or function body. This is necessary for Dinou to know they are Server Components and execute them.
Example
// Server Component example
export default async function ServerComponent() {
// This is a Server Component because it's async and doesn't use directive "use client"
const data = await fetch('https://api.example.com/data');
const result = await data.json();
return (
<div>
<h1>Server Component</h1>
<p>{result.message}</p>
</div>
);
}// Also a Server Component (even without await)
export default async function AnotherServerComponent() {
// Still a Server Component because it's async
return (
<div>
<h1>Another Server Component</h1>
</div>
);
}