Skip to content

Tanstack Query Integration For Solid ​

This guide shows how to integrate oRPC with Tanstack Query for Solid. For an introduction, please review the Basic Guide first.

Installation ​

sh
npm install @orpc/solid-query@latest @tanstack/solid-query@latest
sh
yarn add @orpc/solid-query@latest @tanstack/solid-query@latest
sh
pnpm add @orpc/solid-query@latest @tanstack/solid-query@latest
sh
bun add @orpc/solid-query@latest @tanstack/solid-query@latest
sh
deno add npm:@orpc/solid-query@latest npm:@tanstack/solid-query@latest

Setup ​

Before you begin, ensure you have already configured a server-side client or a client-side client.

ts
import { 
createORPCSolidQueryUtils
} from '@orpc/solid-query'
export const
orpc
=
createORPCSolidQueryUtils
(
client
)
orpc
.
planet
.
find
.
queryOptions
({
input
: {
id
: 123 } })
//

Avoiding Query/Mutation Key Conflicts ​

Prevent key conflicts by passing a unique base key when creating your utils:

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

Usage ​

WARNING

Unlike the React version, when creating a Solid Query Signal, the first argument must be a callback.

ts
import { 
createQuery
} from '@tanstack/solid-query'
const
query
=
createQuery
(
() =>
orpc
.
planet
.
find
.
queryOptions
({
input
: {
id
: 123 } })
)

Released under the MIT License.