🐛(frontend) remove scroll listener table content

During a useEffect cleaning, the selector was
not the correct one. The debounce was not being
removed correctly neither.
This commit is contained in:
Anthony LC
2025-03-10 09:29:33 +01:00
committed by Anthony LC
parent 197ba47f73
commit fdc49dc002
2 changed files with 21 additions and 5 deletions

View File

@@ -48,16 +48,27 @@ export const TableContent = () => {
}
};
document.getElementById(MAIN_LAYOUT_ID)?.addEventListener('scroll', () => {
setTimeout(() => {
let timeout: NodeJS.Timeout;
const scrollFn = () => {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
handleScroll();
}, 300);
});
};
document
.getElementById(MAIN_LAYOUT_ID)
?.addEventListener('scroll', scrollFn);
handleScroll();
return () => {
window.removeEventListener('scroll', handleScroll);
document
.getElementById(MAIN_LAYOUT_ID)
?.removeEventListener('scroll', scrollFn);
};
}, [headings, setHeadingIdHighlight]);