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

Rendering multiple images using Props in React.js

I am trying to render images in my local system to a website using react components. In the "index.js" file I am creating 4 different components with attributes. One of the attributes is the "img". In the "Card.js" file I have created a card component and want to render this 4 times on the page. But, I am unable to link the image to the component properly hence it’s not loading. I have attached the screenshots and the relevant code below.

Component that I need to render multiple times using props

Index.js file where I am passing props to components

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 :

You should import the image, using

<Card img={require('./mj.jpg')} />

or

import mj from './mj.jpg';

<Card img={mj} />

Some reference: How do I reference a local image in React?

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