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>
);
}