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

84
Views
How dynamically import multiple exports from module without knowing their values beforehand

I have a set of SVG icons rendered as React components. Something like that:

 import { IconCancel } from 'icons';

I have backend endpoint that returns array of objects. Each object contains icon name.

Example of object:

{
  title: 'foo',
  icon: 'IconSubmit',
  // other properties...
}

I don't know what icons will be used until i fetch info from backend.

How can i dynamically import icons from icon module after i fetch info from backend?

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

0

You can use dynamically import.

const [listIcon, setListIcon] = useState([]);
useEffect(() => {
    import('icons').then(res =>
        setListIcon(res)
        console.log(res)
    )
}, [])


const Component = listIcon[apiObject.icon]
return <Component />
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!