please i need resource recommendation for pagination on trpc the official docs is very confusing

Please any recommendations will be much appreciated be it video or blog post or code snippet etc
21 Replies
Lopen
LopenOP3y ago
const handlePagination = async (page: number) => {
await push(`/dashboard/company?page=${page}`)
}
const handlePagination = async (page: number) => {
await push(`/dashboard/company?page=${page}`)
}
can't i do pagination without the url changing? like implementing infinite scroll
Neto
Neto3y ago
you can the handlepagination on that was just my lazy way of doing that
Lopen
LopenOP3y ago
oh
Neto
Neto3y ago
Infinite Queries | TanStack Query Docs
Rendering lists that can additively "load more" data onto an existing set of data or "infinite scroll" is also a very common UI pattern. React Query supports a useful version of useQuery called useInfiniteQuery for querying these types of lists. When using useInfiniteQuery, you'll notice a few things are different:
Lopen
LopenOP3y ago
thanks lastly
const data = await ctx.prisma.technology.findMany({
skip: (input.page - 1) * input.limit,
take: input.limit
})
const data = await ctx.prisma.technology.findMany({
skip: (input.page - 1) * input.limit,
take: input.limit
})
the skip and take are the what confused me in the offical doc not the init pagination but the handling next page
Neto
Neto3y ago
if you are on the first page
page = 1
limit = 10
skip = 10
page = 1
limit = 10
skip = 10
you would skip the first 10 rows
Lopen
LopenOP3y ago
page and limit for init then skip for next page? so you will skip the previous pages you have before?
Neto
Neto3y ago
Neto
Neto3y ago
kind of with offset pagination you have that
Lopen
LopenOP3y ago
why pagination1 and pagination2?
Neto
Neto3y ago
two methods
Lopen
LopenOP3y ago
cant have a single function?
Neto
Neto3y ago
to show the difference between the page - 1
Lopen
LopenOP3y ago
i am still lost thou
Neto
Neto3y ago
let me make a better example
Lopen
LopenOP3y ago
okay thanks
Neto
Neto3y ago
Neto
Neto3y ago
basically on the first page you do not want to skip the first N rows from the table
Lopen
LopenOP3y ago
So basically i will need 2 functions for pagination on the client side? Because of handling the skip logic?
Neto
Neto3y ago
no you just need one i was just showing about the page-1

Did you find this page helpful?