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

113
Views
How to dynamically generate id for function components?

Hi I am creating my first application in React. The application generates css styles. It consists of components like border radius, box shadow etc. The components can be combined with each other. Variables from each component are sent via redux to an array and then rendered. I would like to add the possibility of choosing any components and combining them with each other. My problem is with component id. I don't know how to generate id dynamically depending on components order. I need it to update array in redux. There will be an option to delete any components there, so I can't type this statically. I tried to do it using map(), but each component has a different name and I have no idea how to do it. Is it even possible?

Thanks in advance and sorry for my English

const components = [<Transform id={0} />, <BorderRadius id={1} />];
const renderComponents = components.map((component, index) => component);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I don't recommend you to map different components, but if you really have to, wrap it in a fragment like this.

const components = [<Transform />, <BorderRadius />];
const renderComponents = components.map((component, index) => (
  <React.Fragment id={index}>
   {component}
  </React.Fragment>
));

See more about fragments here

https://reactjs.org/docs/fragments.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!