Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

To show images from given data object

I am new to react native i am building a book app UI and i have a doubt

Here is my code

const data = [
{
    id: "1",
    title: "Name",
    image: "https:/images", // i want to import images from my folder instead of fetching data from web
    author: "Author Name",
},

  <Image
    style={{ width:200, height:200, top: -20, left: 65, resizeMode:"contain"}}
    source={{ uri: item.image }} // 👈 here
    />

I am currently using uri for to import images but I want to import from my assets folder and I have no idea how to do it, I apologize for my bad English please help me out

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should use require, due notice that it have to get an actual path (keeping at the object only the path and then require dynamically at implementation not allowed)

{
    id: "1",
    title: "Name",
    image: require("path/to/image"), 
    author: "Author Name",
}


...

<Image
    style={{ width:200, height:200, top: -20, left: 65, resizeMode:"contain"}}
    source={item.image} 
    />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading