@@ -6,7 +6,7 @@ import scrollIntoView from 'scroll-into-view-if-needed';
66import getScroll from '../_util/getScroll' ;
77import type { SemanticClassNamesType , SemanticStylesType } from '../_util/hooks' ;
88import { useMergeSemantic } from '../_util/hooks' ;
9- import { isPlainObject } from '../_util/is' ;
9+ import { isFunction , isNumber , isPlainObject } from '../_util/is' ;
1010import scrollTo from '../_util/scrollTo' ;
1111import { devUseWarning } from '../_util/warning' ;
1212import Affix from '../affix' ;
@@ -257,7 +257,7 @@ const Anchor: React.FC<AnchorProps> = (props) => {
257257 }
258258
259259 // https://github.com/ant-design/ant-design/issues/30584
260- const newLink = typeof getCurrentAnchor === 'function' ? getCurrentAnchor ( link ) : link ;
260+ const newLink = isFunction ( getCurrentAnchor ) ? getCurrentAnchor ( link ) : link ;
261261 setActiveLink ( newLink ) ;
262262 activeLinkRef . current = newLink ;
263263
@@ -273,7 +273,7 @@ const Anchor: React.FC<AnchorProps> = (props) => {
273273
274274 const currentActiveLink = getInternalCurrentAnchor (
275275 links ,
276- targetOffset !== undefined ? targetOffset : offsetTop || 0 ,
276+ isNumber ( targetOffset ) ? targetOffset : offsetTop || 0 ,
277277 bounds ,
278278 ) ;
279279
@@ -304,7 +304,7 @@ const Anchor: React.FC<AnchorProps> = (props) => {
304304 const scrollTop = getScroll ( container ) ;
305305 const eleOffsetTop = getOffsetTop ( targetElement , container ) ;
306306 let y = scrollTop + eleOffsetTop ;
307- y -= targetOffset !== undefined ? targetOffset : offsetTop || 0 ;
307+ y -= isNumber ( targetOffset ) ? targetOffset : offsetTop || 0 ;
308308 animatingRef . current = true ;
309309 scrollRequestIdRef . current = scrollTo ( y , {
310310 getContainer : getCurrentContainer ,
@@ -388,7 +388,7 @@ const Anchor: React.FC<AnchorProps> = (props) => {
388388 } , [ dependencyListItem ] ) ;
389389
390390 React . useEffect ( ( ) => {
391- if ( typeof getCurrentAnchor === 'function' ) {
391+ if ( isFunction ( getCurrentAnchor ) ) {
392392 setCurrentActiveLink ( getCurrentAnchor ( activeLinkRef . current || '' ) ) ;
393393 }
394394 } , [ getCurrentAnchor ] ) ;
0 commit comments