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

>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} 
    />

Leave a Reply