"use client"; import { useState } from "react"; import { api } from "@/trpc/react"; export function LatestPost() { const [latestPost] = api.post.getLatest.useSuspenseQuery(); const utils = api.useUtils(); const [name, setName] = useState(""); const createPost = api.post.create.useMutation({ onSuccess: async () => { await utils.post.invalidate(); setName(""); }, }); return (
Your most recent post: {latestPost.name}
) : (You have no posts yet.
)}