In order to use <Image>
you should give it a static resource. So the problem is here:
[...playerInfo, `require('../img/player${numPlayer}.jpg')`]
you can implement the same functionality using a code like this:
const playerInfo=[
{
"index" : "1",
"item" : require('../img/player1.jpg'),
},
{
"index" : "2",
"item" : require('../img/player2.jpg'),
}
]
But I think if you have a large list of players creating a customized image component will come more handy:
class CustomizedImage extends Component {
constructor(props) {
super(props);
}
render() {
return (
<Image source= {this.props.source}
resizeMode="contain"
style={{ height: this.props.height, width: this.props.width}} />
);
}
}
then use it like this:
<CustomizedImage source= {require(`../img/player${numPlayer}.jpg`)}
height={100}
width={100}
/>
I haven't run this but it should work properly. Also creating your own customized components is a good way for developing an app, since you can change your package (for example use 'react-native-fast-image' instead) or other configs whenever you wish.