learner
learner

Reputation: 234

Changin images on conditions

I want to change my source of image on certain conditions. I tried this

MY IMPORTS

import img1 from '../assets/1.png'
import img2 from '../assets/7.png'

My code

<Image {...(name === 'img1') ? source = { require(img1) } : source = { require(img2) }} style={styles.img} />

but the change doesn't show.

Upvotes: 0

Views: 26

Answers (1)

SDushan
SDushan

Reputation: 4631

Try to replace you code as below,

<Image style={styles.img} source={name === 'img1' ? require("../assets/1.png") : require("../assets/7.png")} />

Hope this help you. Feel free for doubts.

Upvotes: 2

Related Questions