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

297
Vistas
HTML Within Loop Not Rendering in React

I'm attempting to list queried posts in the DOM using Gatsby. The small snippet below should suffice because the Graphql query is correctly fetching data. This snippet is within the component, which is also rendering correctly. I'm new to Gatsby and React, and I hope I'm missing something pretty basic.

<div className="container">
  Hello! // Renders
  {newsItems.map(newsItem => {
    console.log(newsItem.context.id); // Logs each news item id to console correctly
    Hello! // Does not render
    <p>{newsItem.context.id}</p> // Does not render
  })}
</div>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You've used curly braces, so this is how you return component from map function.

{newsItems.map(newsItem => {
    console.log(newsItem.context.id); // Logs each news item id to console correctly
    return (
        <>
            Hello!
            <p>{newsItem.context.id}</p>
        </>
   )
})}

Haven't tried this, but it should work. This also only works if newsItems contains values. React Fragments <>...</> were used because return must only return single component. You could also use <div>...</div> instead of fragment.

Try this.

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