Home > Enterprise >  Iterating through an array is not rendering values
Iterating through an array is not rendering values

Time:08-03

I'm using the code below, but it's not rendering anything the values of my array. I even tested using <Text></Text> or other tags. I know that the array is populated because I get results back when I console.log(imageArray).

        <View>
        {
            imageArray.map((array, index) => {
                <TouchableOpacity key={index}>
                    <Image
                        source={{ uri: array }}
                        style={{ width: 150, height: 150 }}
                    />
                </TouchableOpacity >
            })
        }
    </View>

CodePudding user response:

In your code you are not returning any values while going through the array.

 <View>
    {
        imageArray.map((array, index) => {
            return <TouchableOpacity key={index}> <----- Return statement
                <Image
                    source={{ uri: array }}
                    style={{ width: 150, height: 150 }}
                />
            </TouchableOpacity >
        })
    }
</View>

There are others ways in which you can accomplish what you are trying to do, but without too much rewrite of your code, a simple return statement while iterating the array should do.

CodePudding user response:

    or
 <View>
    {
        imageArray.map((array, index) => 
            <TouchableOpacity key={index}>
                <Image
                    source={{ uri: array }}
                    style={{ width: 150, height: 150 }}
                />
            </TouchableOpacity >
        )
    }
</View>
  • Related