mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
perf(anchor): reduce unnecessary calculations (#42018)
This commit is contained in:
parent
9a6aaac0c0
commit
901957cf02
@ -245,8 +245,6 @@ const AnchorContent: React.FC<InternalAnchorProps> = (props) => {
|
||||
const handleScrollTo = React.useCallback<(link: string) => void>(
|
||||
(link) => {
|
||||
setCurrentActiveLink(link);
|
||||
const container = getCurrentContainer();
|
||||
const scrollTop = getScroll(container, true);
|
||||
const sharpLinkMatch = sharpMatcherRegex.exec(link);
|
||||
if (!sharpLinkMatch) {
|
||||
return;
|
||||
@ -256,6 +254,8 @@ const AnchorContent: React.FC<InternalAnchorProps> = (props) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const container = getCurrentContainer();
|
||||
const scrollTop = getScroll(container, true);
|
||||
const eleOffsetTop = getOffsetTop(targetElement, container);
|
||||
let y = scrollTop + eleOffsetTop;
|
||||
y -= targetOffset !== undefined ? targetOffset : offsetTop || 0;
|
||||
|
Loading…
Reference in New Issue
Block a user