import { type MetaFunction, useFetcher, useLoaderData, useOutletContext } from "@remix-run/react"; import type { ActionFunctionArgs } from "@remix-run/server-runtime"; import { getApi } from "~/bknd"; export const meta: MetaFunction = () => { return [ { title: "New bknd-Remix App" }, { name: "description", content: "Welcome to bknd & Remix!" } ]; }; export const loader = async () => { const api = await getApi(); const limit = 5; const { data: todos, body: { meta } } = await api.data.readMany("todos", { limit, sort: "-id" }); return { todos: todos.reverse(), total: meta.total, limit }; }; export const action = async (args: ActionFunctionArgs) => { const api = await getApi(); const formData = await args.request.formData(); const action = formData.get("action") as string; switch (action) { case "update": { const id = Number(formData.get("id")); const done = formData.get("done") === "on"; if (id > 0) { await api.data.updateOne("todos", id, { done }); } break; } case "add": { const title = formData.get("title") as string; if (title.length > 0) { await api.data.createOne("todos", { title }); } break; } case "delete": { const id = Number(formData.get("id")); if (id > 0) { await api.data.deleteOne("todos", id); } break; } } return null; }; export default function Index() { const ctx = useOutletContext(); const { todos, total, limit } = useLoaderData(); const fetcher = useFetcher(); return (

bknd w/ Remix

Remix Remix
Go to Admin ➝
{ctx.user ? (

Authenticated as {ctx.user.email}

) : ( Login )}
); }