Home > other >  I have images in my public folder in React application, but I am unable to access images folder from
I have images in my public folder in React application, but I am unable to access images folder from

Time:08-14

I cannot access images from public folder into my React application.

const Menu = [
    {
        id: 1,
        image:"images/maggi.jpg",
        name: "Maggi",
        category: "Breakfast",
        price: 30,
        description: "Hi please select maggi here"
    },
]

CodePudding user response:

Try putting a / before images/maggi.jpg like this ->

const Menu = [ 
    { 
        id: 1, 
        image:"/images/maggi.jpg", 
        name: "Maggi", 
        category: "Breakfast", 
        price: 30, 
        description: "Hi please select maggi here" 
    }, 
]

To access the public directory, you need to put a / before the path

CodePudding user response:

If nothing else works, you can try using require method...

    const Menu = [
    {
        id: 1,
        image:require("../public/images/maggi.jpg"),
        name: "Maggi",
        category: "Breakfast",
        price: 30,
        description: "Hi please select maggi here"
    },
]
  • Related