-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (42 loc) · 1.16 KB
/
Copy pathindex.js
File metadata and controls
49 lines (42 loc) · 1.16 KB
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
import React, {Component} from 'react';
import ReactDom from 'react-dom';
import SuperReactInfiniteScroll from '../src/SuperReactInfiniteScroll';
class InfiniteScrollUsage extends Component {
constructor() {
super();
this.MAX_RECORD_LENGTH = 700;
this.state = {
contentList: this.getContent()
};
}
//Random content
getContent() {
let arr = [];
for (let i = 0; i < 100; i++) {
arr[i] = <p key={i}>Javascript is awesome, And I love it!</p>;
}
return arr
};
render() {
const onScrollComplete = () => {
//Async operation | API call
setTimeout(() => {
let newContent = this.state.contentList;
newContent = newContent.concat(this.getContent());
this.setState({
contentList: newContent
});
}, 2000);
};
const loaderElem = <h1> Loading ...</h1>;
return (
<SuperReactInfiniteScroll
loaderElem={loaderElem}
onScrollComplete={onScrollComplete}
dataList={this.state.contentList}
totalDataLength={this.MAX_RECORD_LENGTH}
/>
);
}
}
ReactDom.render(<InfiniteScrollUsage />, document.getElementById('container'));