1

I have a json file

{
        "name": "SAM",
        "id": "001",
        "default_image":"../assets/image.jpeg"
}

In my component, I set a state called profile_image with this data called default_image, but when I use it like this, it throws an error.

<Image 
    style={styles.image} 
    source={{uri: this.state.profile_image}}/>

I have given width and height but still it throws an error. I have even tried all these possible formats but no success.

<Image 
    style={styles.image} 
    source={{this.state.profile_image}}/>

<Image 
    style={styles.image} 
    source={require(this.state.profile_image)}/>
Saurav Dutta
  • 157
  • 3
  • 9

1 Answers1

0

When using uri to display the image it is displayed using this:

<Image style={{width:120, height:80,  marginTop:15,alignSelf:'center'}}
source={{uri: this.state.avatarSource}}/>

So, you are not making any syntax error here.

The problem is with the path of the image you are giving from JSON

Try changing your JSON to this:

{
        "name": "SAM",
        "id": "001",
        "default_image":"/assets/image.jpeg"
}
HarshitMadhav
  • 4,769
  • 6
  • 36
  • 45