forked from bvaughn/react-virtualized
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender-counters.js
65 lines (56 loc) · 1.21 KB
/
render-counters.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const {PureComponent} = React;
const {AutoSizer, List} = ReactVirtualized;
class ListExample extends PureComponent {
render() {
return React.createElement(AutoSizer, null, ({height, width}) =>
React.createElement(List, {
height: height,
overscanRowCount: 0,
rowCount: 1000,
rowHeight: 30,
rowRenderer: this._rowRenderer,
width: width,
}),
);
}
_rowRenderer({index, isScrolling, key, style}) {
return React.createElement(Row, {
index: index,
key: key,
style: style,
});
}
}
class Row extends PureComponent {
constructor(props, context) {
super(props, context);
this.state = {
counter: 0,
};
this._renderCount = 0;
}
render() {
this._renderCount++;
const {counter} = this.state;
const {index, style} = this.props;
return React.createElement(
'div',
{
onClick: () => {
this.setState(state => {
counter: state.counter++;
});
},
style: style,
},
'Row ',
index,
', ',
this._renderCount,
);
}
}
ReactDOM.render(
React.createElement(ListExample),
document.querySelector('#mount'),
);