我在node_modules中有一个库,其中包含50个svg。我渲染了一些显示svg之一的组件。它具有道具svgName
,我想动态导入必要的svg。
// normally svg can be importted in this way
import svg1 from 'lib/1.svg';
const MyComponent = ({svgName}) => {
// I want something like this
const svg1 = import(`lib/${svgName}.svg`);
return (
// this component render svg in circle
<Icon
src={svg1}
/>
);
}
我该怎么做?