Skip to content
Back to skills

Orpc Tanstack Query

ASecurity

Seamlessly integrate oRPC with TanStack Query (React, Vue, Solid, Svelte, Angular).

  • 8 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 12, 2026
businessreactvueangulargit

Works with

  • cli

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 12, 2026

npx -y skills add ali-master/skills --skill orpc-tanstack-query --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Orpc Tanstack Query?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Orpc Tanstack Query
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ali-master-orpc-tanstack-query/badge)](https://www.skillsdirectory.com/skills/ali-master-orpc-tanstack-query)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: oRPC TanStack Query Integration
description: Seamlessly integrate oRPC with TanStack Query (React, Vue, Solid, Svelte, Angular).
license: MIT
metadata:
  author: Ali Torki
  homepage: https://github.com/ali-master
  version: "1.0.0"
---

# Tanstack Query Integration

[TanStack Query](https://tanstack.com/query/latest) is a robust solution for asynchronous state management.

## Installation

```sh
npm install @orpc/tanstack-query@latest
```

## Setup

```ts
import { createTanstackQueryUtils } from '@orpc/tanstack-query'

export const orpc = createTanstackQueryUtils(client)
```

Avoiding key conflicts:

```ts
const userORPC = createTanstackQueryUtils(userClient, { path: ['user'] })
const postORPC = createTanstackQueryUtils(postClient, { path: ['post'] })
```

## Query Options

```ts
const query = useQuery(orpc.planet.find.queryOptions({
  input: { id: 123 },
  context: { cache: true },
}))
```

## Streamed Query Options

For Event Iterator — data is an array of events appended as they arrive:

```ts
const query = useQuery(orpc.streamed.experimental_streamedOptions({
  input: { id: 123 },
  context: { cache: true },
  queryFnOptions: { refetchMode: 'reset', maxChunks: 3 },
  retry: true,
}))
```

## Live Query Options

For Event Iterator — data is always the latest event:

```ts
const query = useQuery(orpc.live.experimental_liveOptions({
  input: { id: 123 },
  context: { cache: true },
  retry: true,
}))
```

## Infinite Query Options

```ts
const query = useInfiniteQuery(orpc.planet.list.infiniteOptions({
  input: (pageParam: number | undefined) => ({ limit: 10, offset: pageParam }),
  context: { cache: true },
  initialPageParam: undefined,
  getNextPageParam: lastPage => lastPage.nextPageParam,
}))
```

## Mutation Options

```ts
const mutation = useMutation(orpc.planet.create.mutationOptions({
  context: { cache: true },
}))

mutation.mutate({ name: 'Earth' })
```

## Query/Mutation Keys

* `.key`: **Partial matching** for revalidation/invalidation
* `.queryKey`: **Full matching** for Query Options
* `.streamedKey`, `.infiniteKey`, `.mutationKey`: full matching variants

```ts
const queryClient = useQueryClient()

queryClient.invalidateQueries({ queryKey: orpc.planet.key() })
queryClient.invalidateQueries({ queryKey: orpc.planet.key({ type: 'query' }) })
queryClient.invalidateQueries({ queryKey: orpc.planet.find.key({ input: { id: 123 } }) })

queryClient.setQueryData(orpc.planet.find.queryKey({ input: { id: 123 } }), (old) => {
  return { ...old, id: 123, name: 'Earth' }
})
```

## Calling Clients

```ts
const planet = await orpc.planet.find.call({ id: 123 })
```

## Reactive Options (Vue/Solid)

```ts
// Options as function
const query = useQuery(
  () => orpc.planet.find.queryOptions({ input: { id: id() } })
)

// Computed options
const query = useQuery(computed(
  () => orpc.planet.find.queryOptions({ input: { id: id.value } })
))
```

## Default Options

```ts
const orpc = createTanstackQueryUtils(client, {
  experimental_defaults: {
    planet: {
      find: {
        queryOptions: {
          staleTime: 60 * 1000,
          retry: 3,
        },
      },
      create: {
        mutationOptions: {
          onSuccess: (output, input, _, ctx) => {
            ctx.client.invalidateQueries({ queryKey: orpc.planet.key() })
          },
        },
      },
    },
  },
})
```

## Error Handling

```ts
import { isDefinedError } from '@orpc/client'

const mutation = useMutation(orpc.planet.create.mutationOptions({
  onError: (error) => {
    if (isDefinedError(error)) {
      // Handle type-safe error
    }
  }
}))
```

## `skipToken` for Disabling Queries

```ts
const query = useQuery(
  orpc.planet.list.queryOptions({
    input: search ? { search } : skipToken,
  })
)
```

## Hydration

To support SSR, extend the serializer:

```ts
import { StandardRPCJsonSerializer } from '@orpc/client/standard'

const serializer = new StandardRPCJsonSerializer({
  customJsonSerializers: [],
})

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      queryKeyHashFn(queryKey) {
        const [json, meta] = serializer.serialize(queryKey)
        return JSON.stringify({ json, meta })
      },
      staleTime: 60 * 1000,
    },
    dehydrate: {
      serializeData(data) {
        const [json, meta] = serializer.serialize(data)
        return { json, meta }
      }
    },
    hydrate: {
      deserializeData(data) {
        return serializer.deserialize(data.json, data.meta)
      }
    },
  }
})
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.