How to change image when a button is clicked on Expo?

I am trying to make an app that shows cat pictures on Expo. I have a cat picture that is displayed originally. I have a button and when I click the button, I want to change the cat picture that is displayed. Here is what I have:

let imageUri = {uri:  ''};

I define a function that changes the imageUri value:

const displayImage = async () => {
  imageUri = {uri: ''}

Then inside of return() I do the following:

    <View style={styles.container}>
        <Text style={styles.text}> Here is a cat picture </Text>
          style = {styles.button}
          onPress = {() => displayImage()}
        <Image source={imageUri} style = {{width: 155, height: 259}} />

However, it does not update the picture.

Source: React – Stack Overflow

November 28, 2021
Category : News
Tags: expo | reactjs

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.