pwuexecP
Convex Community16mo ago
5 replies
pwuexec

Tanstack query with usePaginatedQuery is not working

I'm having trouble using TanStack Query's
usePaginatedQuery
. It doesn’t seem to behave as expected, and TypeScript is throwing errors. Here’s the code and the error I’m encountering:

Working Example

This works fine:

usePaginatedQuery(
  api.tutors.list, // Query function
  {},              // Query arguments
  { initialNumItems: 6 } // Options
);


Problematic Code

However, in this usage:

await opts.context.queryClient.ensureQueryData(
  convexQuery(
    usePaginatedQuery(api.tutors.list, {}, { initialNumItems: 6 })
  )
);


I get the following TypeScript error:

Expected 2 arguments, but got 1.ts(2554)
index.d.ts(101, 182): An argument for 'queryArgs' was not provided.


Observations

-
usePaginatedQuery
seems to expect two required arguments:
- A query function.
- Query arguments (e.g., an object representing the filters, pagination params, etc.).
- In the problematic code, it seems like TypeScript isn’t recognizing the query arguments or options properly, even though they’re provided.


Questions

1. Am I misunderstanding the correct way to use
usePaginatedQuery
within
convexQuery
or
ensureQueryData
?
2. Is this related to how
ensureQueryData
works or some conflict with
convexQuery
?
3. Could this be a TypeScript inference issue, and if so, how can I resolve it?
4. Is
usePaginatedQuery
still supported in the latest version of TanStack Query?

Any help or clarification would be greatly appreciated! If there’s a better pattern for combining
usePaginatedQuery
with
ensureQueryData
, I’d love to know!
Was this page helpful?