npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

trpc-tanstack-svelte-query

v0.1.2

Published

TanStack Svelte Query Integration for tRPC

Readme

trpc-tanstack-svelte-query

TanStack Svelte Query integration for tRPC.

Inspired by @trpc/tanstack-react-query, this package brings the same option-factory API (queryOptions, mutationOptions, queryKey, queryFilter, etc.) to Svelte apps using @tanstack/svelte-query.

Requires @tanstack/svelte-query ^6, @trpc/client & @trpc/server ^11.17.0, svelte ^5.25.0, and typescript >=5.7.2.

Installation

bun add trpc-tanstack-svelte-query @tanstack/svelte-query @trpc/client @trpc/server

Setup

Create a typed tRPC context and client:

// lib/trpc/client.ts
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import { createTRPCContext } from 'trpc-tanstack-svelte-query';
import type { AppRouter } from './routes';

export const client = createTRPCClient<AppRouter>({
  links: [httpBatchLink({ url: '/api/trpc' })],
});

export const { useTRPC, useTRPCClient } = createTRPCContext<AppRouter>();

Wrap your app with TanStack Query and the tRPC provider:

<!-- routes/+layout.svelte -->
<script lang="ts">
  import { QueryClientProvider } from '@tanstack/svelte-query';
  import TRPCProvider from 'trpc-tanstack-svelte-query/TRPCContext.svelte';
  import { client } from '$lib/trpc/client';
  import { queryClient } from '$lib/trpc/queryClient';

  let { children } = $props();
</script>

<QueryClientProvider client={queryClient}>
  <TRPCProvider trpcClient={client} {queryClient}>
    {@render children()}
  </TRPCProvider>
</QueryClientProvider>

Call createTRPCContext() in a module that loads before TRPCProvider mounts (for example lib/trpc/client.ts), so the provider can wire up the context.

Usage

Queries:

<script lang="ts">
  import { createQuery } from '@tanstack/svelte-query';
  import { useTRPC } from '$lib/trpc/client';

  const trpc = useTRPC();

  const addQuery = createQuery(() => trpc.add.queryOptions({ a: 1, b: 2 }));
</script>

{#if addQuery.isPending}
  <p>Loading...</p>
{:else}
  <p>{addQuery.data}</p>
{/if}

Mutations expose the same option-factory API as the React package — mutationOptions() and mutationKey() on mutation procedures:

<script lang="ts">
  import { createMutation } from '@tanstack/svelte-query';
  import { useTRPC } from '$lib/trpc/client';
  const trpc = useTRPC();

  const greetMutation = createMutation(() => trpc.greet.mutationOptions());
  const greetMutationKey = trpc.greet.mutationKey();
</script>

<button onclick={() => greetMutation.mutate({ name: 'world' })}>
  Greet
</button>

API

On each procedure via useTRPC():

  • queriesqueryOptions(), queryKey(), queryFilter()
  • mutationsmutationOptions(), mutationKey()
  • routerspathKey(), pathFilter()

Package exports:

  • createTRPCContext()useTRPC / useTRPCClient backed by Svelte context
  • createTRPCOptionsProxy() — singleton-style setup without a provider
  • TRPCContext.svelte — provider component for trpcClient + QueryClient

For broader tRPC + TanStack Query concepts, see the React package docs; the Svelte API mirrors it closely.