0
I have the following function to create dynamic array.
funcListMap(_ref) {
let list = [];
_ref.map((i) => {
list.push(
<ListItem key={i.id}>
<h1>{i.id}</h1>
<span>{i.descricao}</span>
<img src={require(`'${i.img}'`)} />
<span>{i.valor}</span>
</ListItem>
)
})
return (list);
}
Only it is giving error in the time to load the image
<Img src={require(`'${i.img}'`)} /> // Ou se tentar assim <Img src={require(i.imagens)}/>
But if I put one the way way manually works, ie load the same image for all.
<Img src={require('../statics/imagens/sanduiches/sanduiche-01.png')} />
How to resolve the issue of this code
<Img src={require(`'${i.img}'`)} /> ou <Img src={require(i.imagens)}/>
You don’t need the
require
, just do<img src={i.img}/>
– NoobSaibot
And why in one test you use i.img and in the other use i.images? What is the correct name?
– bfavaretto
It’s because I was testing with other names, but I’m only using i.img anyway, when I’m going to pull a local image doesn’t work. Thus <img src={i.img} /> taking one from the web as http://siteany/image.png, funcinona, but your informing http://localhost/directory/image.png, does not work! does not load local image.
– Alexon da Silva Moreira