Skip to content

Commit 7cf8b9f

Browse files
committed
fix
1 parent a0e771a commit 7cf8b9f

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

packages/heading/src/react/hooks/useTocSideBar.ts

+4-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React from 'react';
33
import { getNode } from '@udecode/plate-common';
44
import {
55
toDOMNode,
6+
useEditorContainerRef,
67
useEditorPlugin,
78
useEditorSelector,
89
} from '@udecode/plate-common/react';
@@ -20,17 +21,9 @@ export const useTocSideBarState = ({
2021
rootMargin = '0px 0px 0px 0px',
2122
topOffset = 0,
2223
}: TocSideBarProps) => {
23-
const { editor, getOptions } = useEditorPlugin(TocPlugin);
24-
const { scrollContainerSelector } = getOptions();
24+
const { editor } = useEditorPlugin(TocPlugin);
2525
const headingList = useEditorSelector(getHeadingList, []);
26-
const scrollContainerRef = React.useRef<HTMLDivElement | null>(null);
27-
28-
React.useEffect(() => {
29-
scrollContainerRef.current = document.querySelector(
30-
scrollContainerSelector ?? `#${editor.uid}`
31-
)!;
32-
// eslint-disable-next-line react-hooks/exhaustive-deps
33-
}, []);
26+
const containerRef = useEditorContainerRef();
3427

3528
const tocRef = React.useRef<HTMLElement>(null);
3629

@@ -39,7 +32,7 @@ export const useTocSideBarState = ({
3932
const [isObserve, setIsObserve] = React.useState(open);
4033

4134
const { activeContentId, onContentScroll } = useContentController({
42-
containerRef: scrollContainerRef,
35+
containerRef,
4336
isObserve,
4437
rootMargin,
4538
topOffset,

0 commit comments

Comments
 (0)