I created a component that renders images
this is the component.
import React, { lazy, Suspense } from "react";
const Icon = (props) => {
const { src } = props;
return (
<img src={src} />
);
};
export default Icon;
then I use it like this
import ExampleIcon from "./../images/icons/example.png";
...
<Icon src={ExampleIcon} />
is there a more efficient way to load the icons? and then just "load" example.png and use it as a source? tried to change it to:
const Icon = (props) => {
const src = lazy(() => import("./../images/icons/" + props.src + ".png"));
return (
<Suspense fallback={<p>loading...</p>}><img src={src} /></Suspense>
);
};
looks like it doesn´t work that way. any other ideas? thanks!