javascript - ReactJS showing list of items -
i have array of objects(a list of comments item), , want display on page. not of comments! first 10 example. , below list wanna render kinda button. , if user wants see next 10 comments, needs click on button.
something 'show more' in 'youtube'.
i can render comments! don't need that. need display 10 comments ... each time button being clicked.
can me please thanks
so let's assume have 20 comments in array
var comments = getcomments() // returns list of 20 comments
then can use slice
first 10 comments, map them actual html
var commentsashtml = comments.slice(0, this.state.limitto).map(comment => { return <li key={comment.id}>{comment.text}</li> });
to add "load more" functionality, have limitto
state
limitto = 10;
and each "load more" action, increment limit 10 example.
onloadmore () { this.setstate({ limitto: this.state.limitto + 10 }); }
Comments
Post a Comment