rspc is no longer maintained. These docs are kept for reference.

The @rspc/solid-query adapter wraps TanStack Query v5 for Solid. This example uses the tuple client and bindings from the quickstart.

To get started first install the required packages.

npm install @rspc/client@0.3.1 @rspc/solid-query@0.3.1 @tanstack/solid-query@5

Then you can do the following:

index.ts
import { QueryClient } from "@tanstack/solid-query";
import { FetchTransport, createClient } from "@rspc/client";
import { createSolidQueryHooks } from "@rspc/solid-query";

import type { ProceduresLegacy as Procedures } from "./bindings";

// You must provide the generated types as a generic and create a transport (in this example we are using HTTP Fetch) so that the client knows how to communicate with your API.
const client = createClient<Procedures>({
  // Refer to the integration your using for the correct transport.
  transport: new FetchTransport("/rspc"),
});

const queryClient = new QueryClient();
const rspc = createSolidQueryHooks<Procedures>();

function SomeComponent() {
  const version = rspc.createQuery(() => ["version", null]);
  const greeting = rspc.createMutation(() => "greet");

  return (
    <>
      <p>{version.data}</p>
      <button onClick={() => greeting.mutate("Ada")}>Greet</button>
    </>
  );
}

function App() {
  return (
    <rspc.Provider client={client} queryClient={queryClient}>
      <SomeComponent />
    </rspc.Provider>
  );
}