Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

91
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda