Search code examples
androidreact-nativeflatlist

Navigation to another screen with data fetched in FlatList


I am trying to navigate to another screen with the value which I fetched in my FlatList.

Just for example :

renderItem={({item}) =>(
     <Text style={styles.FlatListItemStyle} 
        onPress={() => {props.navigation.navigate('AnotherScreen', {item: item.Value1})}} > ID : {item.Value1}
    </Text>
})

here is navigation js.

<Stack.Screen
      name='OneScreen'
      component={OneScreen}
      options={({ route }) => ({
              title: route.params.item.Value1
            })}
/>

so I want to navigate to another screen which uses Value1 as an argument.

but I am getting undefined.

Please help me.


Solution

  • It should be item not item.value

    <Stack.Screen
          name='OneScreen'
          component={OneScreen}
          options={({ route }) => ({
                  title: route.params.item
                })}
          />
    

    You are passing the prop {item:item.value1} so the prop is item thats why you are getting undefined