Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble solving 'source.uri should not be an empty string' in React Native

I'm having trouble solving

source.uri should not be an empty string

in React Native.

I don't understand where this error comes from. I have 3 Flatlist in my component that renders children components with props from the parent as the URI and none of these is empty.

This is the uri part:

<Image style={styles.imageStyle} source={{uri: this.props.url }} />

enter image description here

like image 608
Hugo Avatar asked Feb 22 '18 12:02

Hugo


4 Answers

Here is another solution:

<Image style={styles.imageStyle} source={this.props.url ? {uri: this.props.url } : null} />
like image 186
Edicarlos Lopes Avatar answered Oct 21 '22 12:10

Edicarlos Lopes


It is likely an empty string is passed to the uri. If you set the uri as an empty string intentionally like myself to not to display any image for this data, use undefined instead or use it like so:

<Image style={styles.imageStyle} source={{uri: this.props.url !=="" ? this.props.url : undefined }} />
like image 21
Benazir Avatar answered Oct 21 '22 11:10

Benazir


Ok so I managed to fix the issue by adding to the default INITIAL_STATE variable that sets the state of my app and the default value before the actions are executed.

So adding the url below was the fix! But could be any url other than a null value.

profile: { user: { phone: '', email: '', first_name: '', last_name: '', photo: 'http://www.tiptoncommunications.com/components/com_easyblog/themes/wireframe/images/placeholder-image.png', description: '' }, membership: { active: false } }
like image 2
Hugo Avatar answered Oct 21 '22 10:10

Hugo


Other way, can be implemented:

render() {
     const {imageURL} = this.state;
     <Image source={{uri:imageURL ? imageURL : null}} style={styles.tinyLogo}/>
}
like image 1
Swift Avatar answered Oct 21 '22 12:10

Swift