Server Components
Learn about Server Components in dinou.
Overview
Server Components in this implementation 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 the framework 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
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>
);
}