Skip to content

Commit

Permalink
Merge pull request #35 from game-node-app/dev
Browse files Browse the repository at this point in the history
Fix for unnecessary fetches when no more results exist for /explore
  • Loading branch information
Lamarcke authored Mar 16, 2024
2 parents 8f48ca1 + faca912 commit 39e9831
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/pages/explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,16 @@ const Index = () => {
}, []);

useEffect(() => {
const canFetchNextPage = !isError && !isFetching && !isLoading;
const lastElement =
trendingGamesQuery.data?.pages[
trendingGamesQuery.data?.pages.length - 1
];
const canFetchNextPage =
!isError &&
!isFetching &&
!isLoading &&
lastElement != undefined &&
lastElement.pagination.hasNextPage;
if (canFetchNextPage && entry?.isIntersecting) {
trendingGamesQuery.fetchNextPage({ cancelRefetch: false });
}
Expand Down

0 comments on commit 39e9831

Please sign in to comment.