ygor perezY
tRPC3y 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})
}}

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
Was this page helpful?