0

I am trying to random the posts like this enter image description here

i had tried like this also

<FlatList
      data={this.state.posts[Math.floor(Math.random() * 
        this.state.posts.length)]}
      // numColumns={1}
      horizontal={false}
      keyExtractor={(elem, index) => elem.id}
      renderItem={(elem)=>(
        <PostListItem style={{ marginTop: 10, width: "100%" }}
        title={elem.item.tieude}
        description={elem.item.mota}
        image={{uri:`${elem.item.imgUrl}`}}
      />
      )}/>  

but no work! Please help me!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

You're passing a single element from posts to the FlatList as data. You should be passing the whole list instead, but shuffle it first. If that is what you actually need to do, then you can consult this thread.

giotskhada
  • 2,326
  • 1
  • 11
  • 18