MCPcopy
hub / github.com/bvaughn/react-window / getEstimatedSize

Function getEstimatedSize

lib/core/getEstimatedSize.ts:4–28  ·  view source on GitHub ↗
({
  cachedBounds,
  itemCount,
  itemSize
}: {
  cachedBounds: CachedBounds;
  itemCount: number;
  itemSize: number | SizeFunction<Props>;
})

Source from the content-addressed store, hash-verified

2import { assert } from "../utils/assert";
3
4export function getEstimatedSize<Props extends object>({
5 cachedBounds,
6 itemCount,
7 itemSize
8}: {
9 cachedBounds: CachedBounds;
10 itemCount: number;
11 itemSize: number | SizeFunction<Props>;
12}) {
13 if (itemCount === 0) {
14 return 0;
15 } else if (typeof itemSize === "number") {
16 return itemCount * itemSize;
17 } else {
18 const bounds = cachedBounds.get(
19 cachedBounds.size === 0 ? 0 : cachedBounds.size - 1
20 );
21 assert(bounds !== undefined, "Unexpected bounds cache miss");
22
23 const averageItemSize =
24 (bounds.scrollOffset + bounds.size) / cachedBounds.size;
25
26 return itemCount * averageItemSize;
27 }
28}

Callers 3

getOffsetForIndexFunction · 0.90
ListFunction · 0.85

Calls 1

assertFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…