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

92
Vistas
how to fetch array with map from other js file in react?

I want to fetch array from the product file but it is showing 'Uncaught TypeError: _product__WEBPACK_IMPORTED_MODULE_1___default(...).map is not a function' I have even tried using key in Col but still it is showing the same. My react code is

import product from '../product'

export default function HomeScreen() {
    return (
        <>
            <h1>Latest Products</h1>
            <Row>
                {product.map((products)=>(
                    <Col sm={12} md={6} lg={4} xl={3}>
                        <h3>{products.name}</h3>
                    </Col>
                ))}
            </Row>
        </>
    )
}

and product file is

const product=[
    {
        _id:'1',
        name : 'Shoes',
        images : './img.shoe4.jfif',
        discription : 'Lorem10j,jdscjscjc nxkd kdn ddksad asdkjdhsadb',
        brand : 'Apple',
        category : 'Electronics',
        price : 89.3,
        countInStocks : 3,
        rating: 4.5,
        numReviews: 4
    }  

];
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You have to export products from your products file.

Either use default export:

export default product;

and use the following import:

import product from '../product';

or use a named import:

export const product = [{ ... }]

and import the named const:

import { product } from '../product'
about 4 years ago · Juan Pablo Isaza Denunciar

0

the actual problem is that the product in your HomeScreen is not an array, seems like you are not exporting your product array from its file,

it should be like this :

//don't forget the export keyword if you want to access it outside this file
const product=[
    {
        _id:'1',
        name : 'Shoes',
        images : './img.shoe4.jfif',
        discription : 'Lorem10j,jdscjscjc nxkd kdn ddksad asdkjdhsadb',
        brand : 'Apple',
        category : 'Electronics',
        price : 89.3,
        countInStocks : 3,
        rating: 4.5,
        numReviews: 4
    }  
];
export default product;
about 4 years ago · Juan Pablo Isaza Denunciar
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