From faca912f6c788b3d8d049df8169681b1349f7690 Mon Sep 17 00:00:00 2001 From: Lamarcke Date: Sat, 16 Mar 2024 08:22:24 -0300 Subject: [PATCH] Fix for unnecessary fetches when no more results exist for /explore --- src/pages/explore/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/explore/index.tsx b/src/pages/explore/index.tsx index 19f5ad5..0744b45 100644 --- a/src/pages/explore/index.tsx +++ b/src/pages/explore/index.tsx @@ -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 }); }