简体   繁体   中英

How to map over axios array to display image

I want to display an image from my data. It works when I use Flatlist but Flatlist has conflicts with ScrollView, so I had to change my displaying method from Flatlist to mapping with component.

First name renders when I use {profile.first_name}, but the image won't render. I believe the issue is in the source = {} of the Image. I have tried profile.banner_picture and that has not worked either.

  const bannerPicture = () => {
    return profile.map((profile) => {
      return (
        <View key={profile.key} 
        style={{padding: 1}}>
          
          <Image
            source={banner_picture}
            style = {{     
              height: 100,
              width: 100,
            }}/>
            <Text>{profile.first_name}</Text>           
        </View>
      );
    });
  };
  

When I change

source = {banner_picture} 


//to this 


source={{uri: banner_picture}}


// it works
  const bannerPicture = () => {
    return profile.map((profile) => {
      return (
        <View key={profile.key} 
        style={{
          flex: 1,
          height: 400,
          width: 400,
          padding: 1}}>
          
          <Image
            source={{uri: banner_picture}}
            style = {{     
              height: 100,
              width: 100,
            }}/>
            <Text>{profile.first_name}</Text>
        </View>
      );
    });
  };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM