I have data in such format:
const data = [
{
id: '0',
title: 'Some title 1'
},
{
id: '1',
title: 'Some title 2'
}
...
]
and I have a folder with images where every image is called '0.png', '1.png', etc, the same amount as the data array length. What I'm trying to do is to map through the data array, displaying the title and the image with the same name as the element's id. For example,
<Image source={require('./images/0.png')} />
So I wrote this piece of code:
data.map(item => (
<View>
<Image source={require(`./images/${item.id}.png`)} />
<Text>{item.title}</Text>
</View>
))
which gives me this error: Error: TransformError: Invalid call at line 36: require("./images/" + item.id + ".png")
I've also tried it this way:
<Image source={require('./images/' + item.id + '.png')} />
When I console.log the path to the image that's created using this concatenation, it looks okay.
By the way, this works just fine:
<Image source={require('./images/' + 10 + '.png')} />
and it displays the image named '10.png'
Am I missing something? Please help!