({
cellComponent: CellComponentProp,
cellProps: cellPropsUnstable,
children,
className,
columnCount,
columnWidth,
defaultHeight = 0,
defaultWidth = 0,
dir,
gridRef,
onCellsRendered,
onResize,
overscanCount = 3,
rowCount,
rowHeight,
style,
tagName = "div" as TagName,
...rest
}: GridProps<CellProps, TagName>)
| 24 | * Either static sizes or something that can be derived (from the data in `CellProps`) without rendering. |
| 25 | */ |
| 26 | export function Grid< |
| 27 | CellProps extends object, |
| 28 | TagName extends TagNames = "div" |
| 29 | >({ |
| 30 | cellComponent: CellComponentProp, |
| 31 | cellProps: cellPropsUnstable, |
| 32 | children, |
| 33 | className, |
| 34 | columnCount, |
| 35 | columnWidth, |
| 36 | defaultHeight = 0, |
| 37 | defaultWidth = 0, |
| 38 | dir, |
| 39 | gridRef, |
| 40 | onCellsRendered, |
| 41 | onResize, |
| 42 | overscanCount = 3, |
| 43 | rowCount, |
| 44 | rowHeight, |
| 45 | style, |
| 46 | tagName = "div" as TagName, |
| 47 | ...rest |
| 48 | }: GridProps<CellProps, TagName>): ReactElement { |
| 49 | const cellProps = useMemoizedObject(cellPropsUnstable); |
| 50 | const CellComponent = useMemo( |
| 51 | () => memo(CellComponentProp, arePropsEqual), |
| 52 | [CellComponentProp] |
| 53 | ); |
| 54 | |
| 55 | const [element, setElement] = useState<HTMLDivElement | null>(null); |
| 56 | |
| 57 | const isRtl = useIsRtl(element, dir); |
| 58 | |
| 59 | const { |
| 60 | getCellBounds: getColumnBounds, |
| 61 | getEstimatedSize: getEstimatedWidth, |
| 62 | startIndexOverscan: columnStartIndexOverscan, |
| 63 | startIndexVisible: columnStartIndexVisible, |
| 64 | scrollToIndex: scrollToColumnIndex, |
| 65 | stopIndexOverscan: columnStopIndexOverscan, |
| 66 | stopIndexVisible: columnStopIndexVisible |
| 67 | } = useVirtualizer({ |
| 68 | containerElement: element, |
| 69 | containerStyle: style, |
| 70 | defaultContainerSize: defaultWidth, |
| 71 | direction: "horizontal", |
| 72 | isRtl, |
| 73 | itemCount: columnCount, |
| 74 | itemProps: cellProps, |
| 75 | itemSize: columnWidth, |
| 76 | onResize, |
| 77 | overscanCount |
| 78 | }); |
| 79 | |
| 80 | const { |
| 81 | getCellBounds: getRowBounds, |
| 82 | getEstimatedSize: getEstimatedHeight, |
| 83 | startIndexOverscan: rowStartIndexOverscan, |
nothing calls this directly
no test coverage detected
searching dependent graphs…