www/versioned_docs/version-10.x/client/react/introduction.mdx
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.
:::tip If you are using Next.js we recommend using our integration with that instead :::
This library enables usage directly within React components
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>
);
}
The wrapper abstracts some aspects of React Query for you: