I want to lazy load SVGs with CRA, but damn I'm stuck and need your help.
I'm trying to do something like this:
const LoadIcon = (name) => lazy(() => import(`../icons/${name}.svg`));
const SvgComponent = ({ icon }) => {
const Icon = LoadIcon(icon);
console.log("Icon ", Icon);
return <Icon />;
};
It's worth to mention that I did tried what official CRA suggest(without lazy load tho):
import { ReactComponent as Icon } from "../icons/myCoolSvg.svg";
But this kind of destructuring doesn't work with lazy.
Please help!