fix lint in TOC

This commit is contained in:
Paul Irish
2025-12-20 18:19:45 -08:00
committed by Rishikanth Chandrasekaran
parent 5d11f318d5
commit 2db72409da

View File

@@ -29,7 +29,8 @@ export function TableOfContents() {
};
});
setHeadings(items);
// Defer the state update to avoid "setState in effect" warning and render cascades
const timeoutId = setTimeout(() => setHeadings(items), 0);
const observer = new IntersectionObserver(
(entries) => {
@@ -44,7 +45,10 @@ export function TableOfContents() {
elements.forEach((elem) => observer.observe(elem));
return () => observer.disconnect();
return () => {
clearTimeout(timeoutId);
observer.disconnect();
};
}, [location.pathname]);
if (headings.length === 0) return null;