pyRPC
← Back to Blog

Migrating from createClient to TanStack hooks

·7 min read

You already have:

const client = createClient<Types>({ baseUrl })
const user = await client.get_user({ id: 1 })

Hooks are the same procedures with caching:

const api = createReactClient<Types>({ baseUrl })
const { data: user } = api.get_user.useQuery({ id: 1 })

Keep both

Adapters expose api.client (and Next’s api.createCaller()) for Promise-style calls in loaders, scripts, and Server Actions. You do not have to delete createClient usage overnight.

Mark mutations on the server

When you adopt hooks, annotate writes with @rpc.mutation and regenerate types so useMutation is the typed path.

Query vs mutation