Last active
August 29, 2015 14:15
-
-
Save flarnie/57f9e9cc8838dcd30176 to your computer and use it in GitHub Desktop.
React-Waypoint Infinite Scroll Step 3
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
var InfiniteScrollExample = React.createClass({ | |
_loadMoreItems: function() { | |
this.setState({ loading: true }); | |
// Do the fetching of data here with AJAX | |
// In this fake example we just generate more image urls | |
// and set the state of 'loading' to false. | |
// ... | |
}, | |
getInitialState: function() { | |
// set up list of items ... | |
}, | |
_renderItems: function() { | |
return this.state.items.map(function(imageUrl, index) { | |
// ... generate list items here ... | |
}); | |
}, | |
_renderWaypoint: function() { | |
if (!this.state.isLoading) { | |
return ( | |
<Waypoint | |
onEnter={this._loadMoreItems} | |
threshold={2.0} | |
/> | |
); | |
} | |
}, | |
render: function() { | |
return ( | |
<div className="infinite-scroll-example"> | |
<div className="infinite-scroll-example__scrollable-parent"> | |
{this._renderItems()} | |
{this._renderWaypoint()} | |
</div> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment