mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 10:03:31 +00:00
Default to the first ID as being active in scroll detection (#3036)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user