简体   繁体   中英

How can I access all of the data from my first flatlist while in an item so I can pass it to my second flatlist?

  1. I have two flatlists in React Native
  2. First flatlist contains a dataset for all my posts. This data is rendered into Posts
  3. Second flatlist contains a datset for all the posts the users has liked. This data is rendered into Posts
  4. The user can navigate while in their home feed to liked posts ( all in same stack navigator). I would like to pass the dataset from the my first flatlist to my second flatlist
  5. I can't figure out how to access all the data of the first flatlist when I am in a post (an item of the first flatlist). I can only access that current item's data
  6. Is there any way to access all of the data from the first flatlist while in an item (post) so I can pass it to my second flatlist. I am currently repulling the data when navigating between the screens which seems suboptimal

You will have to raise your state up. If the first and second lists have the same parent component, store the post data on the parent and send it to each child as a prop. Or use a React context to store the post data and have your flatlists consume it with useContext.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM