T
tRPC

Get undefined when the refetch function has successfully worked

Get undefined when the refetch function has successfully worked

Sstiffjobs5/7/2023
In my use case, I first disabled the useQuery function because I want it only fetch when I want to. And by triggering the refetch, I can see in the browser console showing that my request succeeded by when I want to use the returned data which destructured from the useQuery , it shows undefined. I don't know why this happened.
await refetchDocument();
if (fetchDocumentError) throw fetchDocumentError;
console.log("existingDocument");
if (existingDocument?.checksum === checksum) return;

if (existingDocument !== undefined || existingDocument !== null) {
await deleteSections({ documentId: existingDocument!.id });
if (deleteSectionsError) throw deleteSectionsError;
}
await refetchDocument();
if (fetchDocumentError) throw fetchDocumentError;
console.log("existingDocument");
if (existingDocument?.checksum === checksum) return;

if (existingDocument !== undefined || existingDocument !== null) {
await deleteSections({ documentId: existingDocument!.id });
if (deleteSectionsError) throw deleteSectionsError;
}
I'm using pnpm : "@trpc/client": "^10.18.0", "@trpc/next": "^10.18.0", "@trpc/react-query": "^10.18.0", "@trpc/server": "^10.18.0",
Solution:
I think the proper way of doing my expectation is to use useMutation
Jump to solution
Nnlucas5/7/2023
Can you share a more complete snippet of your code? Looks like you might be trying to consume the data in useQuery using stale variables from the component scope
Solution
Sstiffjobs5/7/2023
I think the proper way of doing my expectation is to use useMutation
Sstiffjobs5/7/2023
I've done it properly Thanks for your response!
Sstiffjobs5/7/2023
I was trying to fetch the data when my function need it and use it afterward, the problem of using useQuery is that it doesn't change the data value immediately
Nnlucas5/7/2023
Yep mutation might be a good way

Looking for more? Join the community!

T
tRPC

Get undefined when the refetch function has successfully worked

Join Server
Recommended Posts
Having trouble to import my AppRouter in my react clientEnvironment: Node v18.15.0 I created my TRPC router in my express app and exported it how -documeArgument of Type not assignableSeeing the following error while trying to establish a connection with the trpc server from the clieCan't I create multiple TRPC React using same Router?Im using monorepo and have 2 client projects on that. I have 2 files that does the same, create the what is architectural style of nextjs + prisma + trpc app?like REST.... or SOA?Types with enabled: falseHow do types work with enabled: false? Do I need to cast my arguments in the cases where enabled is Error: No QueryClient set, use QueryClientProvider to set oneHello! I have wrapped my _app.tsx properly and I have made useQuery functionality possible, howeverYou're trying to use @trpc/server in a non-server environmentEnvironment: Node v18.15.0, yarn, Next 13.2.4 What's wrong: When using `createServerSideHelpers`, iTRPC Middleware w/ InputHello! I was wondering if there is a way to add input fields onto a TRPC middleware. Essentially I Server side headers are not appliedHi guys I have the following trpc client initialized ``` import { createTRPCProxyClient, httpBatchLiGet tRPC procedure latency?Hi all, is there a supported mechanism to run common code to all procedures, say if I want to get laDoes or will trpc support http event stream?Does or will trpc support http event stream?Can't get wsLink's retryDelayMs to workI'm trying to add some backoff for when connecting to my websocket server fails. I've got the followcreateTRPCNext and createTRPCProxyClient within one NextJs appHey, Is there any possibility to use createTRPCNext and createTRPCProxyClient clients in one NextJs Calling axios requests not workingIf i call an API using axios in trpc query procedure It works if the url is https it dont if url is Best practices in naming and defining procedures when they don't fit into standard buckets?I am loving TRPC and its type safety, but I feel like I'm struggling with the naming of procedures. Separating routers into their own modules and merging them causes "any" type in clientHi all, I've separated my router into multiple files, but when merging them I get `any` types for aCan i use try/catch in procedures?can i use try/catch in procedures to pass the error when catching errors in my functions?custom query functionI have a use case where I need a trpc procedure call when a specific key is not present in the localTRPC type checking during build failsEnvironment: node 18.6.0, yarn Whats wrong: Type checking at build time fails. . I think this mightcreateTRPCNext config ctx always returns undefined.Hi Everyone. So I'm trying to use TRPC and Nextjs for auth and post query etc. I have client side c