JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://fb.me/JSXTransformer-0.5.1.js"></script>
<script src="http://fb.me/react-with-addons-0.5.1.js"></script>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
<script>
/*! react-infinite-scroll - v 0.1.1 - guillaumervls 2014-01-13 */
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){function c(a){return a?a.offsetTop+c(a.offsetParent):0}b.exports=function(a){return a.addons&&a.addons.InfiniteScroll?a.addons.InfiniteScroll:(a.addons=a.addons||{},a.addons.InfiniteScroll=a.createClass({getDefaultProps:function(){return{pageStart:0,hasMore:!1,loadMore:function(){},threshold:250}},getInitialState:function(){this.pageLoaded=this.props.pageStart},componentDidMount:function(){this.attachScrollListener()},componentDidUpdate:function(){this.attachScrollListener()},render:function(){var b=this.props;return a.DOM.div(null,b.children,b.hasMore&&b.loader)},scrollListener:function(){var a=this.getDOMNode(),b=void 0!==window.pageYOffset?window.pageYOffset:(document.documentElement||document.body.parentNode||document.body).scrollTop;c(a)+a.offsetHeight-b-window.innerHeight<Number(this.props.threshold)&&(this.props.loadMore(this.pageLoaded+=1),this.detachScrollListener())},attachScrollListener:function(){this.props.hasMore&&(window.addEventListener("scroll",this.scrollListener),this.scrollListener())},detachScrollListener:function(){window.removeEventListener("scroll",this.scrollListener)},componentWillUnmount:function(){this.detachScrollListener()}}),a.addons.InfiniteScroll)}},{}],2:[function(a){var b=a("./react-infinite-scroll");"function"==typeof...
CSS
.samplePage {
font-size: 36px;
line-height: 96px;
}
.loader {
color: red;
}
JavaScript 1.7
/** @jsx React.DOM */
function createDiv(page) {
return ( < div className = "samplePage" > {
'Hello page ' + page + ' !'
} < /div>
);
}
var Wrapper = React.createClass({
getInitialState: function () {
return {
hasMore: true,
items: [createDiv(0)]
};
},
loadMore: function (page) {
console.log('load');
setTimeout(function () {
this.setState({
items: this.state.items.concat([createDiv(page)]),
hasMore: (page < 15)
});
}.bind(this), 1000);
},
render: function () {
console.log('render');
var InfiniteScroll = React.addons.InfiniteScroll;
return (
<InfiniteScroll loader={<div className="loader">Loading ...</div>} loadMore={this.loadMore} hasMore={this.state.hasMore}>
{this.state.items}
</InfiniteScroll > );
}
});
React.renderComponent(Wrapper(), document.body);