Navigating to each item in FlatList

后端 未结 1 572
野的像风
野的像风 2021-02-11 07:37

I have a list of products and need to navigate to each product from that list and show data passed from HomeScreen do DetailsScreen.I\'m trying to navigate between screens using

1条回答
  •  日久生厌
    2021-02-11 08:14

    Assuming that your data is being passed as the navigation and the components are connected, and your Item Component is your DetailsScreen therefore you can do the following

    openDetails = (data) => {
        this.props.navigation.navigate("Details", { 
          data  <== // ... pass the item data here
        });
      };
    
           this.openDetails(item)} // Get the item data by referencing as a new function to it
            itemUrl={item.imageUrl}
            data={this.state.data}
          />
    

    DetailsScreen.js

    Wrap your view in TouchableOpacity to access Touchable events

     //... Bind the openDetails function to the prop here
       {JSON.stringify(this.props.itemTitle)} //...<== Access the other props here
     
    

    0 讨论(0)
提交回复
热议问题