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

212
Vistas
How do I get rid of - Warning: Each child in a list should have a unique "key" prop

How can I get rid of this warning. I hate seeing it in the console. I feel I'm doing everything right but I keep getting this warning. This is what I'm doing:

      {reviews.map((review, i) => {
    return (
      <>
        <sl-details summary={`${review.name}`} key={i} open>
          <p>{review.review}</p>
        </sl-details>
        <br />
      </>
    );
  })}

I don't know if the stack is of any relevance but I'm using Nextjs and shoelace.

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

0

You didn't position your key on the first node within your map's callback.

Fragments declared with the explicit <React.Fragment> syntax may have keys. A use case for this is mapping a collection to an array of fragments

Checkout the very last section of that page.

So your code should become:

{reviews.map((review, i) => {
    return (
      <React.Fragment key={i}>
        <sl-details summary={`${review.name}`} open>
          <p>{review.review}</p>
        </sl-details>
        <br />
      </React.Fragment>
    );
  })}
about 4 years ago · Juan Pablo Isaza Denunciar

0

The key={i} should be put on the outer <></> elements, and for that to be possible, you need to convert them to full <Fragment> elements.

Updated code:

{reviews.map((review, i) =>
    <Fragment key={i}>
      <sl-details summary={`${review.name}`} open>
        <p>{review.review}</p>
      </sl-details>
      <br />
    </Fragment>
)}

PS I also shortened it to not use the unneeded return.

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