I have an index page where there is a list of users , if user clicks on each user it goes to their profile screen , I can pass the id to render the profile screen but the problem is the profile page is made of several components , and I need that received data to be used in components.
Here is how I pass the data to user's profile:
onPress={() => this.props.navigation.navigate('userProfile',{item})}>
Here is how I receive it in userProfile :
export default class UserProfileScreen extends React.Component {
render() {
const {item} = this.props.navigation.state.params;
return (
<ScrollView>
<View style={styles.container}>
<IntroCard item={item}/>
</View>
</ScrollView>
}
}
and this is how I receive data in <IntroCard>
component:
const IntroCard = (props) => {
return (
<View>
<Text>{this.props.item ? this.props.item.id : 'default'}</Text>
</View>
)}
But after doing all of these I get the following error:
TypeError: TypeError: TypeError: undefined is not an object (evaluating '_this.props.item')