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

Function useItemSize

lib/core/useItemSize.ts:4–33  ·  view source on GitHub ↗
({
  containerSize,
  itemSize: itemSizeProp
}: {
  containerSize: number;
  itemSize: number | string | SizeFunction<Props>;
})

Source from the content-addressed store, hash-verified

2import type { SizeFunction } from "./types";
3
4export function useItemSize<Props extends object>({
5 containerSize,
6 itemSize: itemSizeProp
7}: {
8 containerSize: number;
9 itemSize: number | string | SizeFunction<Props>;
10}) {
11 let itemSize: number | SizeFunction<Props>;
12 switch (typeof itemSizeProp) {
13 case "string": {
14 assert(
15 itemSizeProp.endsWith("%"),
16 `Invalid item size: "${itemSizeProp}"; string values must be percentages (e.g. "100%")`
17 );
18 assert(
19 containerSize !== undefined,
20 "Container size must be defined if a percentage item size is specified"
21 );
22
23 itemSize = (containerSize * parseInt(itemSizeProp)) / 100;
24 break;
25 }
26 default: {
27 itemSize = itemSizeProp;
28 break;
29 }
30 }
31
32 return itemSize;
33}

Callers 1

useVirtualizerFunction · 0.90

Calls 1

assertFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…