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

143
Views
Should a key be directly on your component or on the container element within your component?

If I want to return one of my components from a map, can I just do this?

<Component data={data} key={`component-${data.id}`} />

or, are you supposed to do something like this, within the component itself?

const Component = ({data}) => {
  return (
     <div key={`component-${data.id}`}>
     // Rest of component
     </div>
  )
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Both approaches are fine they work both its your own personal preference honestly I think if you do it like the first example you won't get warnings I assume you're trying something like this hope this clears it up if not let me know

return (
    <>
      {Dataa.map((data) =>
        <Component data={data} key= 
        {`component-${data.id}`} />
      )}
    </>
  );

Refer docs for further clarification: https://reactjs.org/docs/lists-and-keys.html

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!