Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

209
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!