I think this is a very annoying bug and feels like there is no solution but I want to share and ask.. I fetch data from server and I get image source from there and I use same Image paths in my mobile react-native App.
I fetch data from server like this :
$id = $request->userid;
$items = DB::table('item_user')->where('user_id', $id)->latest()->get();
$new = new Collection();
foreach($items as $item){
$new[] = array(
... ,
'picturePath' => 'require'."('./". $item->picturePath ."')"
);
}
return $new;
and in front-end I try to render and I have these images locally. So when I use it locally like :
require('./images/...')
It works.. but like this its not working :
_renderItem = ({item}) => {
return(
<View>
<Image source={ item.picturePath } style={{width: 15, height: 15}}/>
</View>
);
};
render(){
return(
<View>
<FlatList
data={this.state.items}
renderItem={this._renderItem}
keyExtractor={this._keyExtractor}
/>
</View>
);
}
and I get error, How I can solve this :
Warning: Failed prop type: Invalid prop 'source' supplied to 'Image'.