blob: 41f99669e69a32ff238bfa1a32e9e1bb79703d2f (
plain)
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
|
import React, { useCallback } from 'react';
import { Poll } from 'which-types';
import { WindowScroller, AutoSizer, List } from 'react-virtualized';
import RenderItem from './RenderItem';
interface PropTypes {
polls: Poll[];
mutate: (polls: Poll[], refetch: boolean) => void;
}
const PollsList: React.FC<PropTypes> = ({ polls, mutate }) => {
const rowRenderer = useCallback(({ index, style, key }) => (
<RenderItem
polls={polls}
mutate={mutate}
index={index}
style={style}
key={key}
_key={key}
/>
), [polls, mutate]);
return (
<WindowScroller>
{({
height,
isScrolling,
registerChild,
onChildScroll,
scrollTop
}) => (
<AutoSizer disableHeight>
{({ width }) => (
<div ref={registerChild}>
<List
autoHeight
height={height}
isScrolling={isScrolling}
onScroll={onChildScroll}
rowCount={polls.length}
rowHeight={550}
rowRenderer={rowRenderer}
scrollTop={scrollTop}
width={width}
containerStyle={{ pointerEvents: 'auto' }}
overscanRowCount={2}
/>
</div>
)}
</AutoSizer>
)}
</WindowScroller>
);
};
export default PollsList;
|