diff --git a/themes/fukasawa/components/Catalog.js b/themes/fukasawa/components/Catalog.js index b9ed5809..dc924a7c 100644 --- a/themes/fukasawa/components/Catalog.js +++ b/themes/fukasawa/components/Catalog.js @@ -1,4 +1,4 @@ -import React, { useRef } from 'react' +import React, { useCallback, useRef } from 'react' import throttle from 'lodash.throttle' import { uuidToId } from 'notion-utils' import { useGlobal } from '@/lib/global' @@ -28,7 +28,7 @@ const Catalog = ({ toc }) => { // 同步选中目录事件 const [activeSection, setActiveSection] = React.useState(null) const throttleMs = 200 - const actionSectionScrollSpy = React.useCallback(throttle(() => { + const actionSectionScrollSpy = useCallback(throttle(() => { const sections = document.getElementsByClassName('notion-h') let prevBBox = null let currentSectionId = activeSection @@ -52,6 +52,7 @@ const Catalog = ({ toc }) => { } setActiveSection(currentSectionId) const index = tocIds.indexOf(currentSectionId) || 0 + console.log('滚动目录', tRef.current) tRef?.current?.scrollTo({ top: 28 * index, behavior: 'smooth' }) }, throttleMs)) @@ -60,10 +61,10 @@ const Catalog = ({ toc }) => { return <> } - return
+ return
{locale.COMMON.TABLE_OF_CONTENTS}
-
-