0

I am trying to load files with variables

my current implementation:

const map = {
  google: import('./svg/google.svg'),
  microsoft: import('./svg/microsoft.svg')
}
const Image = ({ name }) => {
  //assume map[name] always exists
  const Component = map[name];
  return (
    <Component />
  )
}

the above snippet works perfectly. now the requirement is to add another 400 companies. Well, i don't want to create & maintain a map with 400 keys. so I am wondering if there is any better to do that? i.e. load the file with variable

something like

import(`./svg/${name}.svg`)

0 Answers0