Answer the question
In order to leave comments, you need to log in
How to set the path to an image in a loop?
I have all the data stored in a separate state.js file, for example:
let state = {
body: {
home: {
news:[
{
image: './image/name.jpeg',
title: 'title '
}
]
}
}
}
{this.props.news.map((item,index) => {
return(
<div className={cl.event} key={index}>
<img src={item.image} alt=""/>
<div className={cl.title}>
<a href="/">{item.title}</a>
</div>
</div>
)
})}
import logo from '../images/logo.jpg'
let state = {
body: {
home: {
news:[
{
image: logo,
title: 'title '
}
]
}
}
}
<img src={__dirname + item.image} alt=""/>
Answer the question
In order to leave comments, you need to log in
This approach seems very strange to me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question