Skip to content

Commit

Permalink
fix: prevent render loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Nov 21, 2024
1 parent bc53faf commit 83f3260
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/app/explorer/components/InfiniteScrollGuilds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ export const InfiniteScrollGuilds = () => {
});

useEffect(() => {
if (isFetchingNextPage) return;
if (!isFetchingNextPage) {
resetIsIntersected();
}
}, [resetIsIntersected, isFetchingNextPage]);

useEffect(() => {

Check warning on line 50 in src/app/explorer/components/InfiniteScrollGuilds.tsx

View workflow job for this annotation

GitHub Actions / quality-assurance

lint/correctness/useExhaustiveDependencies

This hook does not specify all of its dependencies: isLoading
if (isFetchingNextPage || isLoading) return;
if (isIntersected && hasNextPage) {
fetchNextPage();
}
resetIsIntersected();
console.log("what", { isLoading, isFetchingNextPage });
}, [isIntersected, hasNextPage, isFetchingNextPage, fetchNextPage]);

const guilds = data?.pages.flatMap((page) => page.items);
const guilds = data?.pages.flatMap((page) => page.items) || [];

return (
<section className="grid gap-2">
Expand All @@ -60,15 +66,18 @@ export const InfiniteScrollGuilds = () => {
<Skeleton className="size-full h-[114px]" />
</Card>
))
: guilds?.map((guild) => <GuildCard key={guild.id} guild={guild} />)}
: guilds.map((guild) => <GuildCard key={guild.id} guild={guild} />)}
</div>

<div
ref={(element: HTMLDivElement | null) => {
ref={useCallback((element: HTMLDivElement | null) => {

Check warning on line 72 in src/app/explorer/components/InfiniteScrollGuilds.tsx

View workflow job for this annotation

GitHub Actions / quality-assurance

lint/correctness/useExhaustiveDependencies

This hook does not specify all of its dependencies: setIntersection
setIntersection(element);
}}
}, [])}
aria-hidden
/>
{guilds.length === 0 &&
!isLoading &&
search &&
`No results for "${search}"`}
<Button
className="mt-8"
onClick={() => fetchNextPage()}
Expand Down

0 comments on commit 83f3260

Please sign in to comment.