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

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

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 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