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

223
Vistas
How to eliminate empty node with loop inside React JSX

how right to filter data from an object and then render it? I found a suitable working solution, but the problem is that I have to return an empty node, otherwise I will get an error: ``` Array.prototype.map() expects a value to be returned at the end of arrow function:

const movieRows = Object.entries(movieObject).map(([key, value], id) => {
  if (
    key === "Actors" ||
    key === "Director" ||
    key === "Country" ||
    key === "Runtime"
  ) {
    return (
      <tr key={id}>
        <td className="title">{`${key}:`}</td>
        <td className="value">{`${value}`}</td>
      </tr>
    );
  } else {
    // this
    return <></>;
  }
});

Even that is not quite good, because I get a message to the console that it is necessary to add a key.

So I'm returning an unnecessarily empty node, just to satisfy React.

else {
    return <tr key={id}></tr>;
  }

Is there any way to write this without an unnecessary node?

Thanks

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

0

Thanks to Nick, the solution is:

const movieRows = Object.entries(movieObject)
    .filter(
      ([key]) =>
        key === "Actors" ||
        key === "Director" ||
        key === "Country" ||
        key === "Runtime"
    )
    .map(([key, value], id) => {
      return (
        <tr key={id}>
          <td className="movie-subtitle">{`${key}:`}</td>
          <td>{`${value}`}</td>
        </tr>
      );
    });
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