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} />

>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} />

Live Demo

Edit Load icon through props in img src (forked)

Leave a Reply