style: site code optimization (#42685)

* style: site code optimization

* fix
pull/42705/head
lijianan 2 years ago committed by GitHub
parent 25883ca53a
commit 7b066a9211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,8 @@ import * as React from 'react';
import scrollTo from '../../../../components/_util/scrollTo'; import scrollTo from '../../../../components/_util/scrollTo';
import useSiteToken from '../../../hooks/useSiteToken'; import useSiteToken from '../../../hooks/useSiteToken';
const listenerEvents = ['scroll', 'resize'] as const;
const useStyle = () => { const useStyle = () => {
const { token } = useSiteToken(); const { token } = useSiteToken();
@ -105,13 +107,10 @@ const AffixTabs: React.FC = () => {
}, []); }, []);
React.useEffect(() => { React.useEffect(() => {
window.addEventListener('scroll', onSyncAffix); listenerEvents.forEach((event) => window.addEventListener(event, onSyncAffix));
window.addEventListener('resize', onSyncAffix);
onSyncAffix(); onSyncAffix();
return () => { return () => {
window.removeEventListener('scroll', onSyncAffix); listenerEvents.forEach((event) => window.removeEventListener(event, onSyncAffix));
window.removeEventListener('resize', onSyncAffix);
}; };
}, []); }, []);

Loading…
Cancel
Save