rembrembdocs

tRPC offers a first class integration with React. Under the hood this is simply a wrapper around the very popular @tanstack/react-query, so we recommend that you familiarise yourself with React Query, as their docs go in to much greater depth on its usage.

The tRPC React Query Integration

This library enables usage directly within React components

pages/IndexPage.tsx

tsx

import { trpc } from '../utils/trpc';

export default function IndexPage() {

const helloQuery = trpc.hello.useQuery({ name: 'Bob' });

const goodbyeMutation = trpc.goodbye.useMutation();

return (

`<div>`

  `<p>{helloQuery.data?.greeting}</p>`

  `<button onClick={() => goodbyeMutation.mutate()}>Say Goodbye</button>`

`</div>`

);

}

Differences to vanilla React Query

The wrapper abstracts some aspects of React Query for you: