Matt Laszcz
Matt Laszcz

Reputation: 409

Get the image source from a react native <Image> component

Is there a way for me to retrieve the image source uri "profileImage" from the image component and pass it to the function, profileImageFilter(), as 'image source'.

I want 'image source' to be the "uri: profileImage" value

<TouchableOpacity onPress={profileImageFilter('image source')}>
     <Image style={styles.profileimage} source={{uri: profileImage}}></Image>
</TouchableOpacity>

Upvotes: 0

Views: 465

Answers (1)

Ben Walton
Ben Walton

Reputation: 453

If You have access to profile image in the render function then why don't you just past it to the function?

See example:

<View>

<TouchableOpacity onPress={() => profileImageFilter({uri: profileImage})}>
     <Image style={styles.profileimage} source={{uri: profileImage}}></Image>
</TouchableOpacity>

<TouchableOpacity onPress={() => profileImageFilter({uri: profileImage2})}>
     <Image style={styles.profileimage} source={{uri: profileImage2}}></Image>
</TouchableOpacity>

<TouchableOpacity onPress={() => profileImageFilter({uri: profileImage3})}>
     <Image style={styles.profileimage} source={{uri: profileImage3}}></Image>
</TouchableOpacity>

</View>

Upvotes: 1

Related Questions