Last active
December 4, 2017 06:29
-
-
Save taewo/90c02dc2cbdffdf854d306c3623cd6c3 to your computer and use it in GitHub Desktop.
react-infinite es6 version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import Infinite from 'react-infinite'; | |
class CoPropertyPage extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
elements: null, | |
isInfiniteLoading: false, | |
}; | |
this.elementInfiniteLoad = this.elementInfiniteLoad.bind(this); | |
this.handleInfiniteLoad = this.handleInfiniteLoad.bind(this); | |
this.buildElements = this.buildElements.bind(this); | |
} | |
componentDidMount() { | |
const temp = this.buildElements(0, 20); | |
this.setState({ | |
elements: temp, | |
}); | |
} | |
buildElements(start, end) { | |
const elements = []; | |
for (let i = start; i < end; i += 1) { | |
elements.push( | |
<div className="infinite-list-item"> | |
List Item {i} | |
</div> | |
) | |
} | |
return elements; | |
} | |
handleInfiniteLoad() { | |
const that = this; | |
this.setState({ | |
isInfiniteLoading: true | |
}); | |
setTimeout(() => { | |
const elemLength = that.state.elements.length, | |
newElements = that.buildElements(elemLength, elemLength + 30); | |
that.setState({ | |
isInfiniteLoading: false, | |
elements: that.state.elements.concat(newElements) | |
}); | |
}, 1500); | |
} | |
elementInfiniteLoad() { | |
return ( | |
<div className="infinite-list-item"> | |
Loading... | |
</div> | |
) | |
} | |
render() { | |
return ( | |
<Infinite | |
elementHeight={40} | |
containerHeight={250} | |
infiniteLoadBeginEdgeOffset={200} | |
onInfiniteLoad={this.handleInfiniteLoad} | |
loadingSpinnerDelegate={this.elementInfiniteLoad()} | |
isInfiniteLoading={this.state.isInfiniteLoading} | |
> | |
{this.state.elements} | |
</Infinite> | |
) | |
} | |
} | |
export default CoPropertyPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment