In my React Native app, I have a component that contains an Image
whose source
I want to depend on an input prop. I've tried the following two methods:
<Image source={require('@images/'+this.props.image+'.png')}/>
and
<Image source={require(this.props.image === 'a' ? '@images/a.png' : '@images/b.png')}/>
but both throw errors. Can anyone tell me what's wrong with these pieces of code? The only other solution I can think of is
<Image source={require(this.props.image)}/>
and to pass in the pathname of the image as a prop, but I assume there's a cleaner solution.