Cursor rule
.cursor/rules/trpc.mdcHow to use tRPC and react-query in the app
Cursor rules
Quality
40/100
Scores the file, not the repository.Length
451 words
0 headings · 3 code blocksRepository
0
— · pushed 396 days agoLast changed
3 days ago
First indexed 3 days ago.123456The project integrates tRPC with `@tanstack/react-query` by consistently using helper methods provided by the tRPC client. This approach standardizes how queries and mutations are defined and how their respective React Query keys are generated.78Key characteristics of tRPC usage in this codebase:9101. **Client Initialization**:11 * The tRPC client is obtained within custom React hooks using `const trpc = useTRPC()`. This `useTRPC` hook is typically imported from a central client setup file (e.g., `@/client/trpc`).12132. **Using `queryOptions` for Queries**:14 * When setting up queries with `useQuery` from `@tanstack/react-query`, instead of manually defining query keys and fetcher functions, the code leverages a `queryOptions` helper method available on each tRPC query procedure.15 * This method takes the query input as its first argument and an optional object for tRPC/React Query options (like `enabled`) as its second argument.16 * Example:17```typescript18 // In use-conversation-messages.ts19 const messagesQuery = useQuery(20 trpc.message.list.queryOptions(21 conversationId ? { conversationId } : skipToken,22 { enabled: queryEnabled },23 ),24 );2526 // In use-tenant.ts27 const { data: tenant } = useQuery(trpc.tenant.getTenant.queryOptions());28```29303. **Using `mutationOptions` for Mutations**:31 * Similarly, for mutations with `useMutation` from `@tanstack/react-query`, a `mutationOptions` helper method is used. This method is available on each tRPC mutation procedure.32 * It can be called without arguments or with an object containing tRPC-specific options. The result is then spread into the `useMutation` hook's options, often alongside React Query mutation callbacks like `onMutate`, `onSuccess`, `onError`, and `onSettled`.33 * Example:34```typescript35 // In use-chat-assets.ts36 const createPresignedUrlMutation = useMutation(37 trpc.asset.generatePresignedUrl.mutationOptions(),38 );3940 // In use-conversation-delete.ts41 const mutation = useMutation({42 ...trpc.conversation.delete.mutationOptions(),43 onMutate: async (variables) => { /* ... */ },44 onSuccess: () => { /* ... */ },45 // ... other callbacks46 });47```48494. **Generating Query Keys with `queryKey`**:50 * For operations that require direct interaction with the React Query cache (e.g., invalidating queries, setting query data optimistically), a `queryKey` helper method is used. This method is available on tRPC query procedures and takes the query input as an argument.51 * Example:52```typescript53 // In use-conversation-messages.ts54 queryClient.invalidateQueries({55 queryKey: trpc.conversation.list.queryKey({}),56 });5758 queryClient.setQueryData(59 trpc.message.list.queryKey({ conversationId: message.conversationId }),60 // ... updater function61 );62```63645. **Procedure Path**:65 * tRPC procedures are accessed via a path on the initialized `trpc` client object, typically structured as `trpc.namespace.procedureName` (e.g., `trpc.message.list`, `trpc.asset.generatePresignedUrl`).66676. **Integration with `useQueryClient`**:68 * The `useQueryClient` hook from `@tanstack/react-query` is frequently used for cache manipulation tasks like invalidating data, performing optimistic updates, and cancelling outgoing requests, especially within mutation lifecycle callbacks.6970This consistent use of `queryOptions`, `mutationOptions`, and `queryKey` helper methods streamlines the integration with `@tanstack/react-query`, ensuring that query keys are generated correctly and that options are passed in a standardized way. It abstracts away some of the manual setup that might be seen in other tRPC and React Query integrations.71
Also in poglesbyg/htsf-consultant
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| poglesbyg/htsf-consultant.cursor/rules/always.mdc · 0 | Cursor rules | test | 35/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/code-conventions.mdc · 0 | Cursor rules | setuplint-formatstyledo-not+1 | 80/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/crispr-algorithms.mdc · 0 | Cursor rules | deployment | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/data-models.mdc · 0 | Cursor rules | typessecuritydatabase | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/database.mdc · 0 | Cursor rules | typesdatabasedo-not | 61/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/env-vars.mdc · 0 | Cursor rules | securitydo-not | 63/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/react.mdc · 0 | Cursor rules | style | 34/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/shadcn-components.mdc · 0 | Cursor rules | ui | 63/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/smart-polling.mdc · 0 | Cursor rules | no sections | 44/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/trpc-architecture.mdc · 0 | Cursor rules | archtypes | 56/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursor/rules/typescript.mdc · 0 | Cursor rules | styletypesdo-not | 55/100 | 3 days ago | |
| poglesbyg/htsf-consultant.cursorrules · 0 | .cursorrules | archdeploymentagent-behaviour | 48/100 | 3 days ago |
Diff against .cursor/rules/always.mdc Diff against .cursor/rules/code-conventions.mdc Diff against .cursor/rules/crispr-algorithms.mdc Diff against .cursor/rules/data-models.mdc Diff against .cursor/rules/database.mdc Diff against .cursor/rules/env-vars.mdc Diff against .cursor/rules/react.mdc Diff against .cursor/rules/shadcn-components.mdc Diff against .cursor/rules/smart-polling.mdc Diff against .cursor/rules/trpc-architecture.mdc Diff against .cursor/rules/typescript.mdc Diff against .cursorrules
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
