TanStackT
TanStack3y ago
7 replies
radical-lime

how do I prefetch the next page?

I have a custom infiniteQuery hook, and I want to prefetch the next page on success. I'm using TRPC, but I think it's more appropriate to ask in here since it's more RQ related, 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?