Best Practice to Fetch a Query OnDemand
What's the best practice to fetch a query on demand?
I don't have the context for the query's input in the scope of my component. (Using react-hook-form with a zodResolver that has a dynamic refinement based on the fields submitted and a components prop)
M
michaelschufi•341d ago
The thing is. The route is actually a query and not a mutation. But I need to access it in a react-query-mutation-way, because I need it on demand and not in the component lifecycle.
Should I just change the procedure to be a mutation then? It feels wrong (E.g. returning
undefined
would be wrong).AK
Alex / KATT 🐱•341d ago
either you use
enabled:
on the query or you can use useContext
https://trpc.io/docs/reactjs/useContextuseContext | tRPC
useContext is a hook that gives you access to helpers that let you manage the cached data of the queries you execute via @trpc/react-query. These helpers are actually thin wrappers around @tanstack/react-query's queryClient methods. If you want more in-depth information about options and usage patterns for useContext helpers than what we provide...
M
michaelschufi•341d ago
useContext sounds nice, i'll try that! thanks 👍
4.8KMembers
View on DiscordMore Posts
Output Response ShapeI'm wondering, is the output response shape locked in, or can we modify it in any way? For example:
Need help```js
import {initTRPC} from '@trpc/server';
import * as trpcNext from '@trpc/server/adapters/next';useQuery hook modify data on fetch.Hello is it possible to modify the data that is fetched with useQuery hook in tRPC basically im storAccepting a DecoratedProcedure with inputs and outputs that extend some given typesIs there any way to accept a DecoratedProcedure that extends { mutate: Resolver<TProcedure> } where useEffect and useMutation error about conditional rendering of hooksI am using t3 stack with tRPC, and I am trying to mark all emails as seen when the page loads by usiGuide to create an adapterIs there a guide on the docs that explains the basics to create an adapter?Does tRPC websocket client supports wss protocol?After changing the websocket client url from ws to wss, it fails to connect. Tested out the connectiGet the type of context after middlewareHow can I get the type of the context of `adminProcedure` from
`export const adminProcedure = public