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 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));
};
}, []);

Loading…
Cancel
Save