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

Image doesn't appear in ReactJS

I’m creating a mini project in React, I have an issue in the following code;

function Medwiki(props) {
    const medicines = [
        { name: 'Medicine A ', details: 'Details of Medicine A', image: '../assets/pngegg.png' },
        { name: 'Medicine B ', details: 'Details of Medicine B', image: 'https://thumbs.dreamstime.com/z/medicine-capsule-logo-vector-illustration-medicine-capsule-logo-file-format-can-be-scaled-to-any-size-141357083.jpg' },
        { name: 'Medicine C ', details: 'Details of Medicine C', image: 'https://example.com/medicineC.jpg' },
        { name: 'Medicine C',  details: 'Details of Medicine C', image: 'https://example.com/medicineC.jpg' },
        { name: 'Medicine C',  details: 'Details of Medicine C', image: 'https://example.com/medicineC.jpg' },
        { name: 'Medicine C',  details: 'Details of Medicine C', image: 'https://example.com/medicineC.jpg' },
        { name: 'Medicine C',  details: 'Details of Medicine C', image: 'https://example.com/medicineC.jpg' },
      ];
    return (
        <div>
        <div className="top-container">
        MedWiki
        <img src='https://thumbs.dreamstime.com/z/medicine-capsule-logo-vector-illustration-medicine-capsule-logo-file-format-can-be-scaled-to-any-size-141357083.jpg' alt="Logo" style={{ width: '10px', height: '10px' }}/>
        </div>
        <div className="medicine-container">
          {medicines.map((medicine, index) => (
            <div className="medicine-box" key={index}>
              <img src={medicine.image} alt={medicine.name} />
              <div className="medicine-name">{medicine.name}</div>
              <div className="medicine-details">{medicine.details}</div>
            </div>
          ))}
        </div>
      </div>
    );
  }

For Medicine A, the image doesn’t appear, but for the web link it works as in Medicine B

the path for my .js file is src/files and for the image is /src/pngegg.png

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

What might be the issue?

>Solution :

It might not be able to resolve the path of the image. I think you can give it a try with require('path/to/image/')

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