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

136
Visualizações
Undefined variable using .map() react

I'm revisiting an old project for coursework at school but I keep getting an error for an undefined grid variable for generating my grid.

I want to loop for the amount of rows and columns which I want to store the properties for in an array called grid. Then I want to display nodes for the rows and columns in the array with .map().

I'm pretty new to react though and can't seem to find why I can't access the grid array within render().

class PathfinderGrid extends Component {
  constructor(props) {
    super(props)
    this.state = {
      grid: [],
    };
  }
  

  componentDidMount() {
    const grid = createGrid();
    this.setState({ grid });
    //console.log(this.state.grid)
  }

  render() {
    return (
      <div>
        {grid.map((grid) => {
          <div>{ grid }</div>
        })}
      </div >
    );
  }
}



const createGrid = () => {
  let grid = [];
  for (let row = 0; row < 15; row++) {
    let currentRow = [];
    for (let col = 0; col < 50; col++) {
      currentRow.push();
    }
    grid.push(currentRow);
    //console.log(grid);

  }
  return grid;
};

export default PathfinderGrid;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you are using class component, I believe you need to write

 {this.state.grid.map((grid) => {
   return <div>{ grid }</div>
 })}
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