Skip to content

Commit 777df2b

Browse files
committed
fix: only collect height when visible
1 parent 32e6081 commit 777df2b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

examples/basic.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ const Demo = () => {
5050
const [type, setType] = React.useState('dom');
5151
const listRef = React.useRef<ListRef>(null);
5252

53+
React.useEffect(() => {
54+
if (visible) {
55+
listRef.current.scrollTo({
56+
index: 50,
57+
});
58+
}
59+
}, [visible]);
60+
5361
return (
5462
<React.StrictMode>
5563
<div>

src/hooks/useHeights.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default function useHeights<T>(
3737

3838
function collectHeight() {
3939
instanceRef.current.forEach((element, key) => {
40-
if (element) {
40+
if (element && element.offsetParent) {
4141
const htmlElement = findDOMNode<HTMLElement>(element);
4242
heightsRef.current.set(key, htmlElement.offsetHeight);
4343
}

0 commit comments

Comments
 (0)