Isha
Isha

Reputation: 210

Can't add local image to react native app

I'm new to react & I'm trying to add a local image to my react app. This is what i've currently, <Image source={require("images/pic.jpeg")} />

but cant figure out why am i getting this error.

ERROR 00:24 Unable to resolve "images/pic.jpeg" from "App.js"

I've installed the Image component also, and have made a separate images folder. I'm using iOS simulator.

If someone could help me regarding this, it would be great! Thanks in advance!

Upvotes: 0

Views: 1323

Answers (1)

ArtDev
ArtDev

Reputation: 543

  1. You are requiring image with absolute path, which is more likely the reason it is not importing properly.

<Image source={require('./images/pic.jpeg')} />

Please pass the pass which you have in your folder structure and require path would be like above example, with ./ or ../

  1. Another solution to import image source is to obtain image source url.

import picImage from '../../assets/images/pic.jpeg';

and pass this picImage as src value

 <Image source={picImage} />

Upvotes: 1

Related Questions