0
export default function CardImageExample (props) {

  const [path,setpath] = React.useState("'../collections/download-0.jpg'")

  function change(){
    console.log(path)

    if(path == "'../collections/download.jpg'"){
      setpath("'../collections/download-0.jpg'")
    }
    else{
      setpath("'../collections/download.jpg'")
    }
  }

    return (
      <View style={{alignItems: 'center'}}>
        <Card style={{height: 240, width: 280, alignItems: 'center'}}>
          <CardItem bordered button onPress={change}>
            **<Image source={require(path)} />**
          </CardItem>
        </Card>
      </View>
    );
}

the path variable does not work but if i use the path directly it works.. Please save

dan1st
  • 12,568
  • 8
  • 34
  • 67

1 Answers1

0

try passing require inside the path state and then in Image source pass only path instead of require(path)

you can check this other similar question, I think it will help you:

React Native - Image Require Module using Dynamic Names

Marc Victor
  • 96
  • 1
  • 4