forked from mui/material-ui
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathVirtualizedList.js
42 lines (36 loc) · 1008 Bytes
/
VirtualizedList.js
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
39
40
41
42
import React from 'react';
import PropTypes from 'prop-types';
import { makeStyles } from '@material-ui/core/styles';
import ListItem from '@material-ui/core/ListItem';
import ListItemText from '@material-ui/core/ListItemText';
import { FixedSizeList } from 'react-window';
const useStyles = makeStyles(theme => ({
root: {
width: '100%',
height: 400,
maxWidth: 300,
backgroundColor: theme.palette.background.paper,
},
}));
function renderRow(props) {
const { index, style } = props;
return (
<ListItem button style={style} key={index}>
<ListItemText primary={`Item ${index + 1}`} />
</ListItem>
);
}
renderRow.propTypes = {
index: PropTypes.number.isRequired,
style: PropTypes.object.isRequired,
};
export default function VirtualizedList() {
const classes = useStyles();
return (
<div className={classes.root}>
<FixedSizeList height={400} width={300} itemSize={46} itemCount={200}>
{renderRow}
</FixedSizeList>
</div>
);
}