Default to the first ID as being active in scroll detection (#3036)

This commit is contained in:
Samy Pessé
2025-03-25 15:39:45 +01:00
committed by GitHub
parent ae78fc5394
commit 27de1cd01d
@@ -12,11 +12,12 @@ export function useScrollActiveId(
) {
const { rootMargin, threshold = 0.5 } = options;
const [activeId, setActiveId] = React.useState<string | null>(null);
const [activeId, setActiveId] = React.useState<string>(ids[0]);
const sectionsIntersectingMap = React.useRef<Map<string, boolean>>(new Map());
React.useEffect(() => {
setActiveId(null);
const defaultActiveId = ids[0];
setActiveId((activeId) => (ids.indexOf(activeId) !== -1 ? activeId : defaultActiveId));
if (typeof IntersectionObserver === 'undefined') {
return;