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

126
Vistas
TypeError: Cannot read properties of undefined (reading 'map') in react

I get this error, when I try to run my code:

TypeError: Cannot read properties of undefined (reading 'map')

Here is my code:

import React, { Component } from "react";
import _ from "lodash";

class TableBody extends React.Component {
  render() {
    const { data, columns } = this.props;
    return (
      <tbody>
        {data.map((item) => (
          <tr>
            {columns.map((column) => (
              <td>{_.get(item, column.path)}</td>
            ))}
          </tr>
        ))}
      </tbody>
    );
  }
}

export default TableBody;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

if data is something that comes from a remote request it is undefined at the first render, until a response comes. Or maybe you are doing some computation in the parent component in which data is undefined when the component gets render. You can write you code like this:

const { data = [], columns = [] } = this.props;

Which set the values to an empty array if they are undefined.

However be sure that you are passing an array and not something else.

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