From 301c5583825f9cfce03e1d765d2e6323de986242 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Wed, 5 Jan 2022 10:16:06 +0800 Subject: [PATCH] =?UTF-8?q?Toc=20=E5=86=85=E5=AD=98=E6=B3=84=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Toc.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/Toc.js b/components/Toc.js index 8bc6877e..dc543f98 100644 --- a/components/Toc.js +++ b/components/Toc.js @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react' +import React from 'react' import throttle from 'lodash.throttle' import { uuidToId } from 'notion-utils' import Progress from './Progress' @@ -12,8 +12,9 @@ import Progress from './Progress' */ const Toc = ({ toc, targetRef }) => { // 无目录就直接返回空 - if (!toc || toc.length < 1) return <> - + if (!toc || toc.length < 1) { + return <> + } // 监听滚动事件 React.useEffect(() => { window.addEventListener('scroll', actionSectionScrollSpy) @@ -26,7 +27,7 @@ const Toc = ({ toc, targetRef }) => { // 同步选中目录事件 const [activeSection, setActiveSection] = React.useState(null) const throttleMs = 100 - const actionSectionScrollSpy = useCallback(throttle(() => { + const actionSectionScrollSpy = React.useCallback(throttle(() => { const sections = document.getElementsByClassName('notion-h') let prevBBox = null let currentSectionId = activeSection