import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { trpc } from "@/lib/trpc"; import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"; import { InfoIcon, Loader2 } from "lucide-react"; export default function TRPCDemoPage() { return (

tRPC + TaylorDB Demo

Example of type-safe API calls with tRPC

{/* Info Alert */} Template Example This page demonstrates a simple tRPC query. Replace this with your own queries based on your TaylorDB schema. See{" "} apps/server/router.ts to add more procedures. {/* Example: Hello Query */}
); } // ============================================================================ // Example Component: Simple Query // ============================================================================ function HelloExample() { const [name, setName] = useState(""); const { data, isLoading, refetch } = trpc.hello.useQuery( { name: name || undefined }, { enabled: false } // Only run when user clicks button ); const handleQuery = () => { refetch(); }; return ( Example: Hello Query A simple tRPC query to test the connection
setName(e.target.value)} placeholder="Enter your name..." />
{data && (

Response:

{JSON.stringify(data, null, 2)}
)}
); } /** * ============================================================================ * Add Your Own Components Here * ============================================================================ * * Follow this pattern to create your own tRPC queries and mutations: * * 1. Create procedures in apps/server/router.ts * 2. Use trpc..useQuery() for queries (reading data) * 3. Use trpc..useMutation() for mutations (writing data) * 4. Handle loading and error states * 5. Refetch queries after mutations to update the UI * * Example Query: * const { data, isLoading, error } = trpc.items.getAll.useQuery(); * * Example Mutation: * const createMutation = trpc.items.create.useMutation({ * onSuccess: () => { * // Refetch or invalidate queries * }, * }); * * For comprehensive examples, see: * - docs/SHADCN_COMPONENTS_GUIDE.md - UI component patterns * - AGENTS.md - Complete development workflow */