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

166
Vistas
Uncaught TypeError: Cannot read properties of undefined (reading '0')

I have no clue why I am getting this error, I believe the logic is fine.

matchData[0] contains this information:

{    players: ["Disguised Lizard", "DrSpiteful"],
    winner: "DrSpiteful",
    scoreDifference: 1
}

Here's the logic containing Match(props) info:

import React from 'react';
import Match from './Match';
import matchData from '../data/matchData';

function MatchList(props) {
  const oneMatch = matchData[0];
  console.log(oneMatch);
  return (
    <section className="PlayerList MatchList">
      <h1>Match list</h1>
      <Match
        players={oneMatch.players}
        winner={oneMatch.winner}
        scoreDifference={oneMatch.scoreDifference}
        />
    </section>
  );
}

export default MatchList;

I am getting an issue with this line of {props.players[0]} <span>vs</span> {props.players[1]} extracted from the code below:

import React from 'react';

function Match(props) {
  return (
    <article className="Match">
      <h1>
        {props.players[0]} <span>vs</span> {props.players[1]}
      </h1>
      {/* To be shown when there is a winner */}
      <h2>
        {props.winner} is the winner by {props.scoreDifference}!
      </h2>
      {/* To be shown when there is no winner */}
      <h2>No winners yet!</h2>
    </article>
  );
}

export default Match;

Can anyone point out to me what I am doing wrong, I honestly don't see the issue.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you can try this code. I hope this code will help you.

props[players][0]
about 4 years ago · Juan Pablo Isaza Denunciar

0

*** EDIT: I have decided to not access the data directly with the index and instead used a loop ***

There seems to be an issue with React.

when I console log

{console.log(props.players[0])} <span>vs</span> {console.log(props.players[1])}

It returns the appropriate information:

Disguised Lizard vs DrSpiteful

However, my react app just crashes and says:

Match.js:6 Uncaught TypeError: Cannot read properties of undefined (reading '0')
about 4 years ago · Juan Pablo Isaza Denunciar

0

Hope it works. {props.players.length == 0 ? "" : props.players[0]} vs {props.players.length == 0 ? "" : props.players[1]}

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