Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
How to declare file-path in Javascript for object mapping?

I am working on a personal react project for learning and considering to mapping data from a JavaScript object file (not JSON in this case). There are many ways to do it. This method of works for me import product1 from "../../assets/images/products/product1.jpeg"; <img src={ product1 } alt="item_image" /> But I want to do it differently. I want retrieve data from a JavaScript object file (not JSON) using mapping. My data.js file contains data like this-

const data = [
    {
        id: 1,
        title: "Meat",
        price: €2.5,
        category: "Grocery",
        path: "../../assets/images/products/product1.jpeg",
    },    
    {
        id: 2,
        title: "Milk",
        price: €1.25,
        category: "Drink",
        path: "../../assets/images/products/product2.jpeg",
    }
]

export function getData () {
    return data;
}

and mapping data in this way

import { getData } from "./data";
function Product () {

    const product = getData();

    return (
        <>
            {   
                product.map((item) => (
                    <div>
                        <div>
                            <div>
                                <div>
                                    <span> { item.title } </span>
                                </div>
                                <div>
                                    <span> { item.price } </span>
                                </div>
                            </div>
                            <div>
                                <img src={ item.path } alt="item-img" />
                            </div>
                            <div>
                                <div>
                                    <span> { item.category } </span>
                                </div>
                            </div>
                        </div>
                    </div>
                ))
            }
        </>
    );
}

export default Product;

But I failed to get the image from this. After looking on internet, I tried to declare the path property using this method path: "file:///home/user/Documents/testapp/src/assets/images/products/product1.jpeg" Unfortunately this method also failed to get the product image. I am expecting a better solution from the community. --Thanks.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda