Files
remix-render/app/routes/index.tsx
Tommy Parnell 6781fd5fdb init
2022-04-07 10:01:20 -04:00

31 lines
793 B
TypeScript

import type { LoaderFunction } from "@remix-run/node";
import { json } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import type { Note } from "@prisma/client";
import { db } from "~/utils/db.server";
type LoaderData = { notes: Array<Note> };
export const loader: LoaderFunction = async () => {
const data: LoaderData = {
notes: await db.note.findMany(),
};
return json(data);
};
export default function Index() {
const data = useLoaderData<LoaderData>();
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.4" }}>
<h1>Welcome to Remix Heroku</h1>
<p> Notes: </p>
<ul>
{data.notes.map(({ id, name }) => ( <li key={name}>id: {id} name: {name}</li>))}
</ul>
</div>
);
}