import { api } from "~/trpc/server";
import { createPost } from "~/utils/actions";
import { Button } from "~/components/ui/Button";
import { revalidatePath } from "next/cache";
export async function CrudShowcase() {
const latestPost = await api.post.getLatest.query();
async function create(formData: FormData) {
"use server";
await createPost(formData);
revalidatePath("/");
}
return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.text}</p>
) : (
<p>You have no posts yet.</p>
)}
<form action={create} className="flex flex-col gap-2">
<input
type="text"
name="text"
placeholder="Title"
className="w-full rounded bg-primary p-2 text-background"
/>
<Button type="submit">Submit</Button>
</form>
</div>
);
}
import { api } from "~/trpc/server";
import { createPost } from "~/utils/actions";
import { Button } from "~/components/ui/Button";
import { revalidatePath } from "next/cache";
export async function CrudShowcase() {
const latestPost = await api.post.getLatest.query();
async function create(formData: FormData) {
"use server";
await createPost(formData);
revalidatePath("/");
}
return (
<div className="w-full max-w-xs">
{latestPost ? (
<p className="truncate">Your most recent post: {latestPost.text}</p>
) : (
<p>You have no posts yet.</p>
)}
<form action={create} className="flex flex-col gap-2">
<input
type="text"
name="text"
placeholder="Title"
className="w-full rounded bg-primary p-2 text-background"
/>
<Button type="submit">Submit</Button>
</form>
</div>
);
}