Skip to main content


The hooks provided by @trpc/react are a thin wrapper around React Query. For in-depth information about options and usage patterns, refer to their docs on Queries.

You pass a [path, input]-tuple as the first argument. You'll notice that you get autocompletion on the path and automatic typesafety on the input.

If an input-argument is optional, you can omit the , input part of the argument.


Backend code
import * as trpc from '@trpc/server';
import { z } from 'zod';
// Create procedure at path 'hello'
.query('hello', {
// using zod schema to validate and infer input values
input: z
text: z.string().optional(),
resolve({ input }) {
return {
greeting: `hello ${input?.text ?? 'world'}`,
import { trpc } from '../utils/trpc';
export function MyComponent() {
// input is optional, so we don't have to pass second argument
const helloNoArgs = trpc.useQuery(['hello']);
const helloWithArgs = trpc.useQuery(['hello', { text: 'client' }]);
return (
<h1>Hello World Example</h1>
helloNoArgs ({helloNoArgs.status}):{' '}
<pre>{JSON.stringify(, null, 2)}</pre>
helloWithArgs ({helloWithArgs.status}):{' '}
<pre>{JSON.stringify(, null, 2)}</pre>