From 1c230c74264b2e60cd64d96c28400ecfec07dd0f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 26 Apr 2025 17:31:21 -0400 Subject: [PATCH] fix: Double fetch on refactored paginated list --- app/components/PaginatedList.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/components/PaginatedList.tsx b/app/components/PaginatedList.tsx index b289db622e..00e73a5e32 100644 --- a/app/components/PaginatedList.tsx +++ b/app/components/PaginatedList.tsx @@ -195,21 +195,27 @@ const PaginatedList = ({ } }, [allowLoadMore, isFetching, items?.length, renderCount, fetchResults]); - React.useEffect(() => { - void fetchResults(); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - const prevFetch = usePrevious(fetch); const prevOptions = usePrevious(options); - // Equivalent to componentDidUpdate + // Initial fetch on mount React.useEffect(() => { + if (fetch) { + void fetchResults(); + } + }, [fetch]); + + // Handle updates to fetch or options + React.useEffect(() => { + if (!prevFetch || !prevOptions) { + return; // Skip on initial mount since it's handled by the above effect + } + if (prevFetch !== fetch || !isEqual(prevOptions, options)) { reset(); void fetchResults(); } - }, [fetch, options, reset, prevFetch, prevOptions, fetchResults]); + }, [fetch, options, reset, fetchResults, prevFetch, prevOptions]); // Computed property equivalent const itemsToRender = React.useMemo(