0

What i want to do is limit the items, and show only the 12 items.

My Code:

componentDidMount() {
   return fetch(ConfigApp.URL+'json/data_posts.php')
     .then((response) => response.json())
     .then((responseJson) => {
       this.setState({
         isLoading: false,
         dataPosts: responseJson
       }
     })}

render() {
return (
    <FlatList
      data={ this.state.dataPosts }
      renderItem={({item}) => 
            <Image source={{uri: ConfigApp.IMAGESFOLDER+item.post_image}}/>              
keyExtractor={(item, index) => index}
/>
bdroid
  • 606
  • 2
  • 12
  • 27

1 Answers1

0

Try it:

componentDidMount() {
  return fetch(ConfigApp.URL + 'json/data_posts.php')
    .then((response) => response.json())
    .then((responseJson) => {
      this.setState({
        isLoading: false,
        dataPosts: responseJson.filter((elem, index) => {
          return index < 12;
        })
      })
    })
}
Bin Feng
  • 116
  • 3
  • Actually i have a filter on dataPosts responseJson.filter(x => x.post_featured == '1'), i can add (elem, index) => { return index < 12; } ? – bdroid May 05 '18 at 23:24