0

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>
2
  • Does this answer your question? map() return doesn't render in react component Commented Aug 2, 2022 at 1:04
  • use a return statement or remove the arrow function brackets Commented Aug 2, 2022 at 1:09

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.