react native image source from uri or require

Viewed 972

I'm creating an app with native react and I'll like to use an already loaded image if there is no image uploaded from user... so how do I dynamically choose uri or require?

Which is the correct syntax?

here is my code :

var profileImage = "require('../../assets/images/blue.png')";
var profileImageUri = "{uri:'https://randomuser.me/api/portraits/men/43.jpg'}";

return(
      <ScrollView style={styles.scroll}>
        <TouchableOpacity>
            <View style={styles.userImage}>
              <Avatar
                rounded
                size={150}
                title={!this.state.profile_picture ? this.state.firstLetter : ''}
                source={
                    this.state.profile_picture ? profileImage : profileImageUri
                }
              />
            </View>
        </TouchableOpacity>

which do not triggers any error but DO NOT work.

Thanks

1 Answers

Remove the double quotes. It shouldn't be a string.

var profileImage = require('../../assets/images/blue.png');
var profileImageUri = {uri:'https://randomuser.me/api/portraits/men/43.jpg'};
Related