How to implement cursor-based infinite scrolling with prisma + useInfinitequery
How to implement cursor based infinite scrolling in this scenario?
Imagine I have this schema:
I want users to have random ID's for other purposes. Cursor based infinite scrolling requires a sequential and unique id of some sort in table. What is the best way to go about this? It feels a bit weird to add an extra column for that, but I seen no other way.
For example:
Only one id can be used though, so what should I do here?
Possible solution?
35 Replies
Read the tRPC useinfinotequery docs
I already read this: https://trpc.io/docs/useInfiniteQuery
useInfiniteQuery | tRPC
- Your procedure needs to accept a cursor input of any type
And this: https://www.prisma.io/docs/concepts/components/prisma-client/pagination#cursor-based-pagination
Prisma
Pagination (Reference)
Prisma Client supports both offset pagination and cursor-based pagination. Learn more about the pros and cons of different pagination approaches and how to implement them.
And I searched a lot, but I think the last schema I arrived at is sufficient for now, until someone suggests a better strategy
The tRPC page you linked shows how to do it without a cursor field
No, the schema needs a cursor field, how else will you reference the next section, hahahaha
In this scenario they use {myCursor: cursor}
Read the code snippet again and look at where they get the cursor from
myCursor is just an arbitrary field like id
Even in prisma docs it says:
guess what field meets those requirements
Id
Yes, but I don't want my id to be sequential
That's the whole point
It works with uuid also