From 6d82c08933ed96a555f16414f41a6155017d709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Castillo?= Date: Tue, 16 Dec 2025 01:35:16 -0300 Subject: [PATCH] fix: add timeout to avoid multiple calls on scroll at infinte table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Tomás Castillo --- src/components/mui/infinite-table/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/mui/infinite-table/index.js b/src/components/mui/infinite-table/index.js index 92b3e167d..3a0c1f0d9 100644 --- a/src/components/mui/infinite-table/index.js +++ b/src/components/mui/infinite-table/index.js @@ -12,6 +12,7 @@ import TableSortLabel from "@mui/material/TableSortLabel"; import Paper from "@mui/material/Paper"; import TableRow from "@mui/material/TableRow"; import styles from "./styles.module.less"; +import { MILLISECONDS_TO_SECONDS } from "../../../utils/constants"; const MuiInfiniteTable = ({ boxHeight = "400px", @@ -24,11 +25,20 @@ const MuiInfiniteTable = ({ }) => { const { sortCol, sortDir } = options; + const isLoadingRef = React.useRef(false); + const handleScroll = (event) => { + if (isLoadingRef.current) return; + const { scrollTop, scrollHeight, clientHeight } = event.target; // eslint-disable-next-line no-magic-numbers if (scrollTop + clientHeight >= scrollHeight - 20) { + isLoadingRef.current = true; loadMoreData(); + + setTimeout(() => { + isLoadingRef.current = false; + }, MILLISECONDS_TO_SECONDS); } };