tRPCttRPC
Powered by
ygor perezY
tRPC•3y ago•
6 replies
ygor perez

How do I prefetch the nextPage of an infiniteQuery?

I have a custom infiniteQuery hook, and I want to prefetch the next page on success. My current implementation is this:
onSuccess(data) {
  const cursor = data.pages.[data.pages ?.length - 1]?.nextCursor
  console.log(cursor)
  if (cursor?.albums || cursor?.tracks cursor?.artists) {
    void       utils.spotify.getSearch.p refetchInfinite {
searchTerm, limit, cursor: cursor})
}}
onSuccess(data) {
  const cursor = data.pages.[data.pages ?.length - 1]?.nextCursor
  console.log(cursor)
  if (cursor?.albums || cursor?.tracks cursor?.artists) {
    void       utils.spotify.getSearch.p refetchInfinite {
searchTerm, limit, cursor: cursor})
}}

On the console I get this:
the console.log with the cursor {albums: 10, tracks: 10, artists: 10}, the prefetch gets sent with the cursor undefined, but the fetch next page has the right cursor: {albums: 10, tracks: 10, artists: 10}

how is this possible?
image.png
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How do I use the rsc-rq-prefetch example with a protected procedure?
Michael SchaufelbergerMMichael Schaufelberger / ❓-help
2y ago
infiniteQuery always undefined cursor
avalleteAavallete / ❓-help
3y ago
Prefetch forEach
eyalllEeyalll / ❓-help
4y ago
How to prefetch data on the client into the cache?
TomTTom / ❓-help
3y ago