Skip to content

Commit edaf883

Browse files
committed
fix: Only collect exist item height
1 parent b46e7fb commit edaf883

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/List.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,17 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
405405
*/
406406
public collectItemHeights = () => {
407407
const { startIndex, endIndex } = this.state;
408+
const { data } = this.props;
408409

409410
// Record here since measure item height will get warning in `render`
410411
for (let index = startIndex; index <= endIndex; index += 1) {
411-
const eleKey = this.getIndexKey(index);
412-
this.itemElementHeights[eleKey] = getNodeHeight(this.itemElements[eleKey]);
412+
const item = data[index];
413+
414+
// Only collect exist item height
415+
if (item) {
416+
const eleKey = this.getItemKey(item);
417+
this.itemElementHeights[eleKey] = getNodeHeight(this.itemElements[eleKey]);
418+
}
413419
}
414420
};
415421

0 commit comments

Comments
 (0)