<!DOCTYPE html>
<html>
<head>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/react-virtualized/dist/umd/react-virtualized.js"></script>
<link rel="stylesheet" href="https://unpkg.com/react-virtualized/styles.css">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="example">
<!-- This element's contents will be replaced with your code... -->
</div>
<script src="script.js"></script>
</body>
</html>
const { AutoSizer, List } = ReactVirtualized
const ITEMS_COUNT = 98
const ITEM_SIZE = 100
// Render your list
ReactDOM.render(
<AutoSizer>
{({ height, width }) => {
const itemsPerRow = Math.floor(width / ITEM_SIZE);
const rowCount = Math.ceil(ITEMS_COUNT / itemsPerRow);
return (
<List
className='List'
width={width}
height={height}
rowCount={rowCount}
rowHeight={ITEM_SIZE}
rowRenderer={
({ index, key, style }) => {
const items = [];
const fromIndex = index * itemsPerRow;
const toIndex = Math.min(fromIndex + itemsPerRow, ITEMS_COUNT);
for (let i = fromIndex; i < toIndex; i++) {
items.push(
<div
className='Item'
key={i}
>
Item {i}
</div>
)
}
return (
<div
className='Row'
key={key}
style={style}
>
{items}
</div>
)
}
}
/>
)
}}
</AutoSizer>,
document.getElementById('example')
)
html, body, #example {
height: 100%;
margin: 0;
padding: 0;
}
.List {
border: 1px solid black;
box-sizing: border-box;
}
.Row {
width: 100%;
height: 100%;
border-bottom: 1px solid black;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0 0.5rem;
box-sizing: border-box;
}
.Item {
width: 100px;
height: 100px;
display: inline-flex;
flex-direction: row;
justify-content: center;
align-items: center;
border: 1px solid #eee;
}