I'm trying to implement "Show More" feature for my comment section in Reactjs but when I click show more it doesn't load the whole array however it removes the show more link. Here is my code:
var CommentBox = React.createClass({
getInitialState: function() {
return {limit:3 ,showMore:false};
},
showMore:function() {
this.setState({showMore: true, limit: this.props.comments.length});
},
render: function() {
var cls=[];
var length=this.props.comments.length;
if(length >= this.state.limit){
cls=[];
for (var i=0;i<this.state.limit;i++ )
cls.push(this.props.comments[i]);
}
return (
<div className="commentBox">
<CommentList data={cls} />
{length> 3 &&!this.state.showMore? <div><a onClick={this.showMore} >show more</a></div>: null}
</div>
);
}
});
making any change to state.comments doesn't affect the view at all.