Skip to content

Commit 0ba33e4

Browse files
committed
chore: reduce nesting of conditions
1 parent bc2cb8b commit 0ba33e4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/StickyList.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ function StickyList(
1616
) {
1717
const innerRef = useRef();
1818
useEffect(() => {
19-
if (ref.current && innerRef.current) {
20-
if (mode === 'bottom') {
21-
ref.current.scrollTo(innerRef.current.offsetHeight);
22-
} else if (mode === 'top') {
23-
ref.current.scrollTo(0);
24-
}
19+
if (!ref.current || !innerRef.current) {
20+
return;
21+
}
22+
23+
if (innerRef.current.offsetHeight <= ref.current.props.height) {
24+
return;
25+
}
26+
27+
if (mode === 'bottom') {
28+
ref.current.scrollTo(innerRef.current.offsetHeight);
29+
} else {
30+
ref.current.scrollTo(0);
2531
}
2632
}, [itemCount]);
2733

0 commit comments

Comments
 (0)