Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to load a image path through props in react

how to load imported image path to img tag src from the component props. please help

import amy from "./amy.jpg";
<AvatarProfileIcon icon="amy" />

 <img src={props.icon} />

https://codesandbox.io/s/load-icon-through-props-in-img-src-9qzox5

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try wrapping your imported image inside curly braces {} instead of double quotes "" since they are being used for strings.

import amy from "./amy.jpg";

export default function App() {
  return (
    <div className="App">
      <AvatarProfileIcon icon={amy} />
    </div>
  );
}

Live Demo

Edit Load icon through props in img src (forked)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading