-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (49 loc) · 1.09 KB
/
index.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
import React, {Component} from 'react'
import {render} from 'react-dom'
import { Virtual } from '../../src'
import './index.less'
let index = 0
function renderListData(num = 16) {
return Array(num).fill(0).map(() => {
index++
return {
key: index,
title: index,
}
})
}
class Demo extends Component {
virtual = React.createRef()
state = {
listData: renderListData(70)
}
onEndReached = () => {
const {listData} = this.state
const newData = renderListData()
this.setState({
listData: [...listData, ...newData]
})
return newData
}
render() {
return (
<Virtual
ref={this.virtual}
pageSize={15}
recycleStartCount={30}
data={this.state.listData}
onEndReached={this.onEndReached}
renderItem={this.renderItem}
/>
)
}
renderItem = ({item}) => {
return <li
key={item.key}
style={{
backgroundColor: item.title % 2 ? '#999' : '#ccc',
height: item.title % 3 * 100 || 30,
}}>{item.title}</li>
}
}
render(<Demo/>, document.querySelector('#demo'))