DxD
DxD10mo ago

trpc Pagination

Does somebody have any example how can i do pagination in trpc and react query?
3 Replies
vildantursic
vildantursic10mo ago
Hi, I haven't had that usecase but I was mostly refering to Tanstack React Query docs, whatever you do with react query you can do with TRPC wrapper. I would pass query params to trpc route (page, limit) and do logic in trpc route and keep (page and limit) on client. This might help https://tanstack.com/query/v4/docs/react/examples/react/pagination
React Query Pagination Example | TanStack Query Docs
An example showing how to implement Pagination in React Query
DxD
DxD10mo ago
danke i will try it
Nick
Nick10mo ago
You can also do a infinite query which is RQ, but we have a special extension of it for type safety: 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.