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

170
Views
How to allow specific values for an icon dynamic import?

I have created a dynamic import to use icons from our library. It looks something like this:

// icons file
export { ArrowLeft } from './ArrowLeft';
export { ArrowRight } from './ArrowRight';
export { Checked } from './Checked';
export { CircleCar } from './CircleCar';

And this is the component:

import * as Icons from '../../components/Icons';
import * as z from 'zod';

const Schema = z.object({
  content: z.object({
   iconName: z.string()
   })
})

type JustAReactComponentProps = z.infer<typeof Schema>

const JustAReactComponent = ({content}: JustAReactComponentProps) => {
   const SecondaryIcon = Icons[content.iconName] as React.JSXElementConstructor<any>;//is this the correct type btw?
   return <SecondaryIcon />
} 

And lets say that we have 30 icons and someone tries to set iconName as an icon that is not in the list, how can I enforce with Typescript that only the ones in the icons file are enabled to be used?

This question below seems to have the same problem I do but the solutions do not work for me(And I'm not looking for an external package). How to find all imported (in code) dependencies within a TypeScript project?

about 4 years ago · Juan Pablo Isaza
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!