2

I'm trying to make a notes app with attached images. When the user adds an image I save it to my server and then save the path to the image in my server.

{this.state.img ? <Image
              style={stylesCP.image}
              source={{ uri: require(this.state.img)}}
            ></Image> : null}

While the img state contains: /Users/myUser/Study/React-Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_06_08_PMimg.jpg

And I'm getting this error:

Failed building JavaScript bundle.

SHA-1 for file /Users/myUser/Study/React-Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_06_08_PMimg.jpg (/Users/myUser/Study/React-Native/Note/WebApplication1/WebApplication1/images/1_3_2021_5_06_08_PMimg.jpg) is not computed

Can anyone help me with that please?

1 Answers1

2

you needs to specify the local image syntax and path correctly like so, try this let me know

class ImageExample extends Component {
  constructor(props) {
    super(props);
    this.state = {
      img: require('../../Assests/Images/1_3_2021_5_06_08_PMimg.jpg'),
    };
  }
  render() {
    return (
      <View>
        {
          this.state.img ?
          <Image
            source={this.state.img}
          />
          : null
        }
      </View>
    );
  }
}

export default ImageExample;
AsZik
  • 621
  • 1
  • 4
  • 20