diff --git a/.dumi/theme/layouts/ResourceLayout/AffixTabs.tsx b/.dumi/theme/layouts/ResourceLayout/AffixTabs.tsx index 5fc69f312b..5e765b46a1 100644 --- a/.dumi/theme/layouts/ResourceLayout/AffixTabs.tsx +++ b/.dumi/theme/layouts/ResourceLayout/AffixTabs.tsx @@ -5,6 +5,8 @@ import * as React from 'react'; import scrollTo from '../../../../components/_util/scrollTo'; import useSiteToken from '../../../hooks/useSiteToken'; +const listenerEvents = ['scroll', 'resize'] as const; + const useStyle = () => { const { token } = useSiteToken(); @@ -105,13 +107,10 @@ const AffixTabs: React.FC = () => { }, []); React.useEffect(() => { - window.addEventListener('scroll', onSyncAffix); - window.addEventListener('resize', onSyncAffix); + listenerEvents.forEach((event) => window.addEventListener(event, onSyncAffix)); onSyncAffix(); - return () => { - window.removeEventListener('scroll', onSyncAffix); - window.removeEventListener('resize', onSyncAffix); + listenerEvents.forEach((event) => window.removeEventListener(event, onSyncAffix)); }; }, []);