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

128
Visualizações
Creating a table in react using multiple component calls not working

I am trying to create a dynamic table of a sudoku app I am working on but I am unable to see why this code wouldnt work. my base app passes in a ref hook and sends the 9x9 array to the Grid component

return(
      <Grid arr={sudokuBoard.current.board} />
    )

Then in my grid app, it makes a call to the RowComponent using the array.map function

export default function Grid(props){
    let sudokuArray = props.arr;
    return(
        <table>
            {sudokuArray.map((row, ind)=> {
                <RowComponent setkey={ind} rowval={row} />
                })
            }
        </table>
    )
}

Which then calls a tablecell generation function

export default function RowComponent(props){
    return(
        <tr key={props.setkey}>
        {props.rowval.map((item,ind) => {
            <TableItem keyval={item} value={item}/>
        })}
        </tr>
    )
}

And the table cell generating component looks like this

export default function TableItem(props){
    let tableValue = props.value
    console.log(tableValue)
    return(
        <td>{props.value}</td>
    )
}

Any pointers on what could be going wrong? The array gets passed into Grid just fine, but its in the chained calls where things stop working.

Thanks

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

In react/JSX you have to use ( ) around your code block inside the map, instead of { }. Like this:

{sudokuArray.map((row, ind)=> (
  <RowComponent setkey={ind} rowval={row} />
))}
{props.rowval.map((item,ind) => (
  <TableItem keyval={item} value={item}/>
))}

Difference between {} and () with .map with Reactjs this is an answer that explains why.

about 4 years ago · Santiago Gelvez 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