I'm trying to render a list of images from a base component by sending down title and image URL.
Everything works fine if I'm rendering the images like this:
<Image source={require('../assets/images/myImage.png')} /> The issue is coming when I'm trying to render the image from props:
class ListItem extends Component { render() { return ( <View> <Text>{this.props.title}<Text> <Image source={require(this.props.imageUri)} /> </View> ); } }; ListItem.propTypes = { title: PropTypes.string.isRequired, imageUri: PropTypes.string.isRequired, }; As a result, I'm getting the next error:
calls to
requireexpect exactly 1 string literal argument, but this was found:require(this.props.imageUri).
I've also tried to render the images using uri
<Image source={{uri: this.props.imageUri}} /> package.js
"react": "16.3.1", "react-native": "https://github.com/expo/react-native/archive/sdk-27.0.0.tar.gz",
source={this.props.imageUri}? What is an eample value ofthis.props.imageUri? Are you trying to use a relative path or an absolute one?source={this.props.imageUri}- Yes, I did try it. I'm not getting any error but the image is not rendered.this.props.imageUri = ../assets/images/myImage.pngAnd check stackoverflow.com/questions/36460827/… to see if it helps- it doesn't help as I don't want to store my image into thestate. There are about 100 possible combinations of images which may change in the future. I'm looking to send down the path from a Json/APi