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

98
Vistas
Not displaying data, if I delete it React

I'm using react-redux and I have something like this in my code:

<div>
  {episode.charactersList.map((id) => {
        const character = characters.find(
            (el) => String(el.id) === String(id)
        );

        return (
            <div key={uuidv4()}>
                {character ? (
                    <Link to={`/users/${character.id}`}>
                        {" "}
                        {character.name}{" "}
                    </Link>
                ) : (
                    <div key={id}> none</div>
            )}
            </div>
        );
    })}
</div>

The problem with this code is that when I delete one of the characters, I get <div> none </div> displayed. I don't know how to get rid of this since I have to use { character ? ( ...... ). If i skip this line of code the page is displayed before the data is being loaded and I get a error of undefined character.

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

0

To resolve the issue, you could test for a valid value of character before your return statement and abort the character from being rendered by returning null. For example:

<div>
  {episode.charactersList.map((id) => {
        const character = characters.find(
            (el) => String(el.id) === String(id)
        );

        if (!character) {
          return null;
        }

        return (
            <div key={uuidv4()}>
                    <Link to={`/users/${character.id}`}>
                        {" "}
                        {character.name}{" "}
                    </Link>
             </div>
        );
    })}
</div>
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