DEV Community

Cover image for #2 React Query: Infinite Scroll

#2 React Query: Infinite Scroll

Kevin Toshihiro Uehara on January 28, 2024

Hi Folks!!! How are you? Fine? How have you been? As I promissed on the first article about react query, where I talk about this state management ...
Collapse
 
guadalazzo profile image
Guadalupe Jazmin Lazzo

is a great article,
just one thing missing:
const { data, error, fetchNextPage, hasNextPage, isFetching, isLoading } =
useInfiniteQuery({
(...)
initialPageParam: 0,
getNextPageParam: (lastPage, allPages) => {
return lastPage.length ? allPages.length + 1 : undefined;
},
});
initialPageParam is missing

Collapse
 
rajaerobinson profile image
Rajae Robinson

Great article. In React Query v5 you can use maxPages prop with infinite queries to limit the number of stored and refetched pages

Collapse
 
ricardogesteves profile image
Ricardo Esteves • Edited

Great article @kevin-uehara !!! I really enjoyed it, well structured and really insightful. 👌

I will share it if it's ok with you.

Collapse
 
adophilus profile image
Adophilus

Nice article. I want to implement infinite scroll in a project I'm working on but I've got one question. Why did you set the ref on each element in the list you're rendering and not just place it a div that's at the bottom of the list?

Collapse
 
pfedprog profile image
Pavel Fedotov • Edited

Also have a look at QueryClient configuration to improve items speed loading

dhiwise.com/post/optimizing-perfor...

Further, good answer on SO

stackoverflow.com/questions/712861...