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

103
Visualizações
Display element of an array React

I am passing through a variable called 'homeTeam' and when console logged it outputs

    abbreviation: "Uls"
    id: "08ew458ius6f"
    name: "Ulster"

A variable called 'awayTeam' outputs the same array but with data of a different team

I have a bit of code to find out if I need the homeTeam or awayTeam abbreviation;

    const restartTeamAbbrevation = async (homeTeam, startTeamId, awayTeam) => {
    if (startTeamId == {homeTeam.id} ) {
       return homeTeam.abbreviation
    } else {
       return awayTeam.abbreviation
    }}

I then want this value to appear on my front end, i am attempting to use the following code;

        <Modal.Body>
        <Row>
            <Col>
                <div className="d-flex">
                    <span className="py-1">Team: </span>
                    <span className="py-1">{ restartTeamAbbrevation() }</span>
                </div>
            </Col>
        </Row>
        </Modal.Body>

I am getting the error

Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'id')
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Because when you are calling that function, you are not passing the parameters like homeTeam, startTeamId, awayTeam, so when the function is called these values equals to undefined and when you try to access homeTeam.id inside the function, it gives you that error.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try passing arguments to your restartTeamAbbreviation function. Something like this:

        <Modal.Body>
        <Row>
            <Col>
                <div className="d-flex">
                    <span className="py-1">Team: </span>
                    <span className="py-1">{ restartTeamAbbreviation(homeTeam, startTeamId, awayTeam) }</span>
                </div>
            </Col>
        </Row>
        </Modal.Body>

Also you have some strange condition, you might want to do this instead:

if (startTeamId === homeTeam.id ) ...

And one more thing, restartTeamAbbreciation function doesn't need to be async

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