ReactJS showing list of items

nevs nevs

I have an array of objects(a list of comments to some item), and I want to display it on the page. But not all of those comments! First 10 for example. And below that list i wanna render some kinda button. And if a user wants to see next 10 comments, he needs to click on that button.

Something like 'show more' in 'Youtube'.

I can render all those comments! But I don't need that. I need to display 10 comments ... each time the button is being clicked.

Can anyone help me please Thanks

Muhammad Aref

So let's assume that you have 20 comments in an array

var comments = getComments() // returns list of 20 comments

Then you can use slice to get the first 10 comments, then map them to actual HTML

var commentsAsHTML = comments.slice(0, this.state.limitTo).map(comment => {
   return <li key={comment.id}>{comment.text}</li>
});

To add the "Load more" functionality, we will have limitTo state

limitTo = 10;

And with each "Load more" action, we will increment this limit by 10 for example.

onLoadMore () {
   this.setState({
      limitTo: this.state.limitTo + 10
   });
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Showing and hiding List items

From Dev

Showing and hiding a list of items

From Dev

ionic sometimes not showing list items

From Dev

AlertDialog with ArrayAdapter not showing list of items

From Dev

MultiAutoCompleteTextView list items not showing text

From Dev

List showing the last 3 items

From Dev

ViewPagers in a ListView showing blank list items

From Dev

Items not showing in vertical list when resized

From Dev

Angular: Showing only checked items in a checkbox list

From Dev

Polymer iron-list showing outdated items

From Dev

Xamarin Forms List View Showing Row items in Frames

From Dev

Accessibility reading showing items in a listview as list item + header view

From Dev

ReactJS parent/child list items not rendering properly after an item is removed

From Dev

ReactJS parent/child list items not rendering properly after an item is removed

From Dev

Reactjs list of items created with react-redux connect

From Dev

Numbers not showing with list items in ordered list with display: inline-block; and text-overflow: ellipsis;

From Dev

Android Toolbar Items not showing?

From Dev

ActionBar Action Items not showing

From Dev

new items in DataGridViewComboBoxCell not showing

From Dev

UITableView items not showing

From Dev

AutoCompleteBox not showing Selected Items

From Dev

ListView is showing repeatative items?

From Dev

Items of RecyclerView are not showing correctly

From Dev

Items of RecyclerView are not showing correctly

From Dev

XAML ItemsControl items not showing

From Dev

ListView is showing repeatative items?

From Dev

Showing/hiding items - listview

From Dev

ListView not showing text on items

From Dev

Repeater items are not showing horizontally?

Related Related

HotTag

Archive