01Read
Your component is the data layer.
Server components are async functions. Import your database and await it during render. No loaders, no getServerSideProps, no API route in between.
import { db } from '../lib/db';
import { addTodo } from './actions';
export default async function Home() {
const todos = await db.todos.list();
return (
<>
<ul>{todos.map(t => <li key={t.id}>{t.title}</li>)}</ul>
<form action={addTodo}>
<input name="title" />
</form>
</>
);
}