Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda