Search code examples
javascriptreactjsreact-nativereact-props

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>


Solution

  • 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>