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

212
Views
How to render dynamic React component from object

Need to render an imported component, like below, with some props inside my React code. I'm thinking this is simple, but I can't find an answer on Stack overflow for this a format like this. How would this be done? Thank you.

import { HomeIcon } from "../lib/icons";

[{
    title: "Home",
    icon: ({ color }: { color: string }) => <HomeIcon color={color} />,
}].map((item, index) => {
        
   const { title, icon: Icon } = item;

   return (
       <div>
           <Icon color="#fff" /> // Doesn't work!
       </div>
   )

EDIT: Here is the error when running the code below enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

OP: Got it, it was a type issue. 'any' isn't accepted here, we have to define icon like this

          icon: (({ color }: { color: string }) => (
            <HomeIcon color={color} />
          )) as React.ElementType<{ color: string }>,
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!