Quickstart: Set up tRPC-SvelteKit
mainTo integrate tRPC-SvelteKit into your SvelteKit application, follow these steps to set up the router, context, and server handle.
Install dependencies:
yarn add trpc-sveltekit @trpc/server @trpc/clientCreate a tRPC router (e.g., in
lib/trpc/router.ts): Initialize tRPC using your context type and define your procedures.Create a tRPC context (e.g., in
lib/trpc/context.ts): Define an async function that returns the context object used by your procedures.Add the tRPC handle to SvelteKit hooks (in
hooks.server.ts): UsecreateTRPCHandleto bridge SvelteKit requests to your tRPC router.
yarn add trpc-sveltekit @trpc/server @trpc/client