tRPCttRPC
Powered by
onethreadO
tRPC•3mo ago•
3 replies
onethread

prefetchInfiniteQuery example?

Hi, I'm trying to switch to the newer tanstack react query pattern with our existing nextjs codebase, but I keep getting type errors when trying to use
queryClient.prefetchInfiniteQuery
queryClient.prefetchInfiniteQuery
. I noticed there's no
infiniteQueryOptions
infiniteQueryOptions
alternative to
queryOptions
queryOptions
on
trpc.{aRouter}.{procedure}
trpc.{aRouter}.{procedure}
, so I'm assuming I have to configure
queryOptions
queryOptions
somehow to get it to take.

That's on the server, the situation is similar on the client. When I try to pass options to
useInfiniteQuery
useInfiniteQuery
I get the following error:

 Type 'DefinedTRPCQueryOptionsOut<LedgerResponse, LedgerResponse, TRPCClientErrorLike<{ transformer: true; errorShape: DefaultErrorShape; }>, { keyPrefix: false; }>' is missing the following properties from type 'UseInfiniteQueryOptions<unknown, Error, InfiniteData<unknown, unknown>, readonly unknown[], unknown>': getNextPageParam, initialPageParam ts(2769)
 Type 'DefinedTRPCQueryOptionsOut<LedgerResponse, LedgerResponse, TRPCClientErrorLike<{ transformer: true; errorShape: DefaultErrorShape; }>, { keyPrefix: false; }>' is missing the following properties from type 'UseInfiniteQueryOptions<unknown, Error, InfiniteData<unknown, unknown>, readonly unknown[], unknown>': getNextPageParam, initialPageParam ts(2769)


When I try to supply those fields in
queryOptions({...}, {getNextPageParam, initialPageParam})
queryOptions({...}, {getNextPageParam, initialPageParam})
I then get
Object literal may only specify known properties, and 'getNextPageParam' does not exist in type 'UndefinedTRPCQueryOptionsIn
Object literal may only specify known properties, and 'getNextPageParam' does not exist in type 'UndefinedTRPCQueryOptionsIn
Solution
Nm, I see it's documented under the React Query Integration (classic). Must provide a cursor field to unlock the infinite properties. https://trpc.io/docs/client/react/useInfiniteQuery
useInfiniteQuery | tRPC
- Your procedure needs to accept a cursor input of any type (string, number, etc) to expose this hook.
useInfiniteQuery | tRPC
Jump to solution
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?