Shibin Raju Mathew
Shibin Raju Mathew

Reputation: 928

How to use state value inside source of image in react native?

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

Answers (1)

J.plus.123
J.plus.123

Reputation: 107

Try this

render() {
    let value = require("../Assets/images/pic.png");
...
    <Image source={value} />
....}

Upvotes: 1

Related Questions