diff --git a/frontend/src/hooks/useInfiniteScroll.ts b/frontend/src/hooks/useInfiniteScroll.ts index b11115d63..9064e6b34 100644 --- a/frontend/src/hooks/useInfiniteScroll.ts +++ b/frontend/src/hooks/useInfiniteScroll.ts @@ -41,10 +41,6 @@ export const useInfiniteScroll = ({ const [getItems, { isLoading, isFetching }] = useLazyQuery({ ...args } as Args); const getDataRequest = (params: Args) => { - if (isEqual(params, lastRequestParams.current)) { - return Promise.reject(); - } - const request = getItems({ limit, ...params, @@ -90,36 +86,40 @@ export const useInfiniteScroll = ({ return; } - try { - isLoadingRef.current = true; - - const result = await getDataRequest({ - ...argsProp, - ...getPaginationParams(data[data.length - 1]), - } as Args); - - let listResponse: ListResponse; + const requestParams = { + ...argsProp, + ...getPaginationParams(data[data.length - 1]), + }; - if ('data' in result) { - listResponse = result.data; - setTotalCount(result.total_count); - } else { - listResponse = result; - setTotalCount(); + if (!isEqual(requestParams, lastRequestParams.current)) { + try { + isLoadingRef.current = true; + + const result = await getDataRequest(requestParams as Args); + + let listResponse: ListResponse; + + if ('data' in result) { + listResponse = result.data; + setTotalCount(result.total_count); + } else { + listResponse = result; + setTotalCount(); + } + + if (listResponse.length > 0) { + setData((prev) => [...prev, ...listResponse]); + } else { + isDisabledMoreRef.current = true; + } + } catch (e) { + console.log(e); } - if (listResponse.length > 0) { - setData((prev) => [...prev, ...listResponse]); - } else { - isDisabledMoreRef.current = true; - } - } catch (e) { - console.log(e); + setTimeout(() => { + isLoadingRef.current = false; + }, 50); } - - setTimeout(() => { - isLoadingRef.current = false; - }, 50); }; useLayoutEffect(() => {