forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVirtualizedList.tsx
38 lines (33 loc) · 978 Bytes
/
VirtualizedList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React from 'react';
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import { FixedSizeList, ListChildComponentProps } from 'react-window';
const useStyles = makeStyles((theme: Theme) =>
createStyles({
root: {
width: '100%',
height: 400,
maxWidth: 300,
backgroundColor: theme.palette.background.paper,
},
}),
);
function renderRow(props: ListChildComponentProps) {
const { index, style } = props;
return (
<ListItem button style={style} key={index}>
<ListItemText primary={`Item ${index + 1}`} />
</ListItem>
);
}
export default function VirtualizedList() {
const classes = useStyles();
return (
<div className={classes.root}>
<FixedSizeList height={400} width={300} itemSize={46} itemCount={200}>
{renderRow}
</FixedSizeList>
</div>
);
}