Skip to content

Commit c49b272

Browse files
committed
[docs] Add virtualized list example
1 parent 49bb455 commit c49b272

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { makeStyles } from '@material-ui/core/styles';
3+
import ListItem from '@material-ui/core/ListItem';
4+
import ListItemText from '@material-ui/core/ListItemText';
5+
import { FixedSizeList } from 'react-window';
6+
7+
const useStyles = makeStyles(theme => ({
8+
root: {
9+
width: '100%',
10+
height: 400,
11+
maxWidth: 360,
12+
backgroundColor: theme.palette.background.paper } }));
13+
14+
15+
16+
function Row(props) {
17+
const { index, style } = props;
18+
19+
return (
20+
<ListItem button style={style} key={index}>
21+
<ListItemText primary={`Item ${index + 1}`} />
22+
</ListItem>);
23+
24+
}
25+
26+
function VirtualizedList() {
27+
const classes = useStyles();
28+
29+
return (
30+
<div className={classes.root}>
31+
<FixedSizeList height={400} width={360} itemSize={46} itemCount={200}>
32+
{Row}
33+
</FixedSizeList>
34+
</div>);
35+
36+
}
37+
38+
export default VirtualizedList;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import { makeStyles, Theme } from '@material-ui/core/styles';
3+
import ListItem from '@material-ui/core/ListItem';
4+
import ListItemText from '@material-ui/core/ListItemText';
5+
import { FixedSizeList, ListChildComponentProps } from 'react-window';
6+
7+
const useStyles = makeStyles((theme: Theme) => ({
8+
root: {
9+
width: '100%',
10+
height: 400,
11+
maxWidth: 360,
12+
backgroundColor: theme.palette.background.paper,
13+
},
14+
}));
15+
16+
function Row(props: ListChildComponentProps) {
17+
const { index, style } = props;
18+
19+
return (
20+
<ListItem button style={style} key={index}>
21+
<ListItemText primary={`Item ${index + 1}`} />
22+
</ListItem>
23+
);
24+
}
25+
26+
function VirtualizedList() {
27+
const classes = useStyles();
28+
29+
return (
30+
<div className={classes.root}>
31+
<FixedSizeList height={400} width={360} itemSize={46} itemCount={200}>
32+
{Row}
33+
</FixedSizeList>
34+
</div>
35+
);
36+
}
37+
38+
export default VirtualizedList;

docs/src/pages/demos/lists/lists.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,11 @@ Unfortunately it's [not implemented](https://caniuse.com/#search=sticky) by all
8585
## Inset List
8686

8787
{{"demo": "pages/demos/lists/InsetList.js"}}
88+
89+
## Virtualized List
90+
91+
In the following example, we demonstrate how to use [react-window](https://github.com/bvaughn/react-window) with the `List` component.
92+
It renders 200 rows and can easily handle more.
93+
Virtualization helps with performance issues.
94+
95+
{{"demo": "pages/demos/lists/VirtualizedList.js"}}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"@types/react-select": "^2.0.14",
8484
"@types/react-swipeable-views": "^0.13.0",
8585
"@types/react-text-mask": "^5.4.2",
86+
"@types/react-window": "^1.7.0",
8687
"@types/styled-components": "^4.1.11",
8788
"argos-cli": "^0.1.1",
8889
"autoprefixer": "^9.0.0",
@@ -177,6 +178,7 @@
177178
"react-test-renderer": "^16.8.5",
178179
"react-text-mask": "^5.0.2",
179180
"react-virtualized": "^9.21.0",
181+
"react-window": "^1.7.1",
180182
"recast": "^0.17.0",
181183
"recharts": "^1.1.0",
182184
"redux": "^4.0.0",

yarn.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,13 @@
22102210
dependencies:
22112211
"@types/react" "*"
22122212

2213+
"@types/react-window@^1.7.0":
2214+
version "1.7.0"
2215+
resolved "https://registry.yarnpkg.com/@types/react-window/-/react-window-1.7.0.tgz#8dd99822c54380c9c05df213b7b4400c24c9877e"
2216+
integrity sha512-HyxhB3TFL/2WKRi69paA1Ch7kowomhR2eSZe7sJz8OtKuNhzRrlYSteSID7GIUpV95k246iVOlxEXmG2bjZQFA==
2217+
dependencies:
2218+
"@types/react" "*"
2219+
22132220
"@types/react@*", "@types/react@^16.7.10":
22142221
version "16.8.8"
22152222
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.8.tgz#4b60a469fd2469f7aa6eaa0f8cfbc51f6d76e662"
@@ -8993,6 +9000,11 @@ memfs-or-file-map-to-github-branch@^1.1.0:
89939000
resolved "https://registry.yarnpkg.com/memfs-or-file-map-to-github-branch/-/memfs-or-file-map-to-github-branch-1.1.2.tgz#9d46c02481b7eca8e5ee8a94f170b7e0138cad67"
89949001
integrity sha512-D2JKK2DTuVYQqquBWco3K6UfSVyVwmd58dgNqh+TgxHOZdTmR8I130gjMbVCkemDl/EzqDA62417cJxKL3/FFA==
89959002

9003+
"memoize-one@>=3.1.1 <6":
9004+
version "5.0.2"
9005+
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.2.tgz#6aba5276856d72fb44ead3efab86432f94ba203d"
9006+
integrity sha512-o7lldN4fs/axqctc03NF+PMhd2veRrWeJ2n2GjEzUPBD4F9rmNg4A+bQCACIzwjHJEXuYv4aFFMaH35KZfHUrw==
9007+
89969008
memoize-one@^5.0.0:
89979009
version "5.0.0"
89989010
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.0.tgz#d55007dffefb8de7546659a1722a5d42e128286e"
@@ -11463,6 +11475,14 @@ react-virtualized@^9.21.0:
1146311475
prop-types "^15.6.0"
1146411476
react-lifecycles-compat "^3.0.4"
1146511477

11478+
react-window@^1.7.1:
11479+
version "1.7.1"
11480+
resolved "https://registry.yarnpkg.com/react-window/-/react-window-1.7.1.tgz#c1db640415b97b85bc0a1c66eb82dadabca39b86"
11481+
integrity sha512-y4/Qc98agCtHulpeI5b6K2Hh8J7TeZIfvccBVesfqOFx4CS+TSUpnJl1/ipeXzhfvzPwvVEmaU/VosQ6O5VhTg==
11482+
dependencies:
11483+
"@babel/runtime" "^7.0.0"
11484+
memoize-one ">=3.1.1 <6"
11485+
1146611486
react@^16.8.5:
1146711487
version "16.8.5"
1146811488
resolved "https://registry.yarnpkg.com/react/-/react-16.8.5.tgz#49be3b655489d74504ad994016407e8a0445de66"

0 commit comments

Comments
 (0)