T
TanStack3y ago
rare-sapphire

InfiniteQueries page refresh

I have a NextJS app that features products. When a user is browsing products via an infinite scroll and clicks on a product, they go to the product page. When they go back, they're in a route that looks like this: example.com/feed?page=3. How can I use infinite query feature such that when they go to page=3 I have pages=[1,2,3] in cache ready to display? Say these 3 pages aren't in cache. How can I use the useQuery or a useEffect so that it fetches the three pages while the user waits for this to load? Seems like a common flow in infinite scrolls, but haven't found a way to do this via React Query
2 Replies
rare-sapphire
rare-sapphireOP3y ago
(if helpful, I'm also using trpc: https://trpc.io/docs/reactjs/useinfinitequery)
other-emerald
other-emerald3y ago
if the pages are in the cache, they'll just be there. If that data is not in the cache, you can setup a useEffect that triggers fetchNextPage() a bunch of times until that page is loaded

Did you find this page helpful?