I tried using dynamic images in ‘react native’. But there has been a error in that method. How to solve this?
The below code snippet works fine.
const image = require('./path/to/home.jpg');
return (
<View>
<Image source={image}>
</View>
);
But if I change it to a dynamic string,
const image = require({img});
return (
<View>
<Image source={image}>
</View>
);
Then I get an error. So how to display dynamic images in React Native.
Sampath Samaraweera is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2
React Native doesn’t supports dynamic imports as long as metro is involved. You need to write out a full require
path.
See this discussion for more details