Skip to content

Commit 719229f

Browse files
committed
Be explicit in comparisons
1 parent b9950a7 commit 719229f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function hashLinkScroll(hashFragment) {
55
// Push onto callback queue so it runs after the DOM is updated
66
setTimeout(() => {
77
const element = document.getElementById(hashFragment);
8-
if (element) element.scrollIntoView();
8+
if (element !== null) element.scrollIntoView();
99
}, 0);
1010
}
1111

@@ -15,10 +15,10 @@ export function HashLink(props) {
1515
let hashFragment = '';
1616
if (typeof props.to === 'string') {
1717
hashFragment = props.to.split('#').slice(1).join('#');
18-
} else if (typeof props.to === 'object' && props.to.hash) {
18+
} else if (typeof props.to === 'object' && typeof props.to.hash === 'string') {
1919
hashFragment = props.to.hash.replace('#', '');
2020
}
21-
if (hashFragment) hashLinkScroll(hashFragment);
21+
if (hashFragment !== '') hashLinkScroll(hashFragment);
2222
}
2323
return <Link {...props} onClick={handleClick}>{props.children}</Link>;
2424
}

0 commit comments

Comments
 (0)