Reputation: 15
I'm trying to set an image as object in ReactJS but i don't know the syntax , i looked on google but i didn't find anything! I don't know if it's even possible ?
Here's the code:
const items = [
{
src: '../images/hb1.jpg',
altText: 'slide 1',
caption: 'dfjkdfjksdfjk',
header:'something'
},
{
src: '../images/hb1.jpg',
altText: 'slide 1',
caption: ' asdasdasd',
header:'something'
},
{
src:'../images/hb1.jpg',
altText: 'Slide 3',
caption: 'dasjdasdkj',
header:'something'
}
];
i call it later on here:
<img src={item.src} alt={item.altText} />
I tried 'url('../url')' but didn't work!
Upvotes: 0
Views: 1149
Reputation: 18664
Your image path should be relative to the project root images directory of the site.
For example:
Your domain is www.example.com. Your images are placed in your public folder /images
.
Therefore in your app, you should link the image as follows:
<img src='/images/test.png' />
Upvotes: 3