diff --git a/packages/virtualized-lists/Lists/VirtualizedList.js b/packages/virtualized-lists/Lists/VirtualizedList.js index 4efaf669e3d875..33e84cd66d833b 100644 --- a/packages/virtualized-lists/Lists/VirtualizedList.js +++ b/packages/virtualized-lists/Lists/VirtualizedList.js @@ -90,19 +90,6 @@ type State = { pendingScrollUpdateCount: number, }; -function findLastWhere( - arr: $ReadOnlyArray, - predicate: (element: T) => boolean, -): T | null { - for (let i = arr.length - 1; i >= 0; i--) { - if (predicate(arr[i])) { - return arr[i]; - } - } - - return null; -} - function getScrollingThreshold(threshold: number, visibleLength: number) { return (threshold * visibleLength) / 2; } @@ -987,7 +974,8 @@ class VirtualizedList extends StateSafePureComponent { const spacerKey = this._getSpacerKey(!horizontal); const renderRegions = this.state.renderMask.enumerateRegions(); - const lastSpacer = findLastWhere(renderRegions, r => r.isSpacer); + const lastRegion = renderRegions[renderRegions.length - 1]; + const lastSpacer = lastRegion?.isSpacer ? lastRegion : null; for (const section of renderRegions) { if (section.isSpacer) {