Reputation: 928
Want to define image location on constructor and want to use multiple place so my question is how to define state with url and use that state.
I have tried below code
this.state = {
value: '../Assets/images/pic.png',
}
<Image source{require(this.state.value)}/>
but getting errors
require expect exactly 1 string literal argument
Upvotes: 1
Views: 1713
Reputation: 107
Try this
render() {
let value = require("../Assets/images/pic.png");
...
<Image source={value} />
....}
Upvotes: 1