Reputation: 353
I am trying to show an image inside a React Native app, but I am experiencing some issues.
Considering that the runtime value of this.state.icon
is './icons/Icon.png'
, I can't figure out why the first line of code doesn't work (an empty blank space is shown instead of the image), while the second version works properly.
<Image style={styles.Icon} source={this.state.icon} />
<Image style={styles.Icon} source={require('./icons/Icon.png')} />
This kind of solution doesn't work too: source={{uri: './icons/Icon.png'}}
Upvotes: 1
Views: 674
Reputation: 8678
require does not support dynamic loading of modules. Javascript files are statically analysed. See Similar issue athttps://github.com/facebook/react-native/issues/2481
Upvotes: 1