react-lazy-svg icon indicating copy to clipboard operation
react-lazy-svg copied to clipboard

dynamic import

Open branikclimbs opened this issue 2 years ago • 1 comments

Is there a way to import svgs dynamically or use symbol id? I would allow us to create a component that would take the name of the icon as a prop and render an appropriate svg. That would also allow typescript auto-completion as you can make a list of available icon names or make a script that would generate them from the directory. (I am using next.js)

branikclimbs avatar Oct 12 '22 15:10 branikclimbs

hi @branislaav, the base principle of react-lazy-svg is to load the SVG itself dynamically. Instead of directly importing the svg code it just uses an identifier like the SVG URL. If you want to have dynamic imports even for the URLs it would get more difficult especially if you still want to have static type checking support. You could create different sets of icon names (enums) that can be split into different bundles. But I would say the benefit will be very small, and only relevant for gigantic numbers of potential icons

kaoDev avatar Oct 20 '22 07:10 kaoDev