React
- npm
- yarn
- pnpm
- bun
npm install @trpc-chat-agent/react
yarn add @trpc-chat-agent/react
pnpm add @trpc-chat-agent/react
bun add @trpc-chat-agent/react
React exposes 2 primary helpers:
- A react hook to manage a conversation
- A helper component to render messages and tool calls
Coming soon: shadcn components for rendering the messages/tools
Using the right tRPC client
Make sure you use the right tRPC client. When using tRPC in React, you generally wrap the client in react-query
. tRPC Chat Agents uses the raw tRPC client instead.
Conversation hook
The useConversation
hook manages conversation state, including fetching the initial conversation data.
For example:
Rendering the messages
When rendering the messages, it is critical to ensure you avoid unnecessary re-renders. tRPC Chat Agent always returns the same reference for the same object data, so you can safely memoize the rendered data.
To help with memoization, this library provides a RenderMessages
helper component which assists with all the memoization.
Do not pass dynamic props into RenderMessages
prop functions. The functions are memoized, and do not take dependencies. Any changes to external props won't propage through. Instead, using signals via @preact/signals-core
and @preact/signals-react
is recommended.