0

I am trying to print an array of JSX elements:

return (
        <View
        style={[
          commonStyles.sectionContainer,
          commonStyles.spaceBottom1x,
          { width: "100%" },
        ]}
      >
        { ['a', 'b'].forEach((letter) => { 

            <View>
                <Text>Hola</Text>
            </View>
        })}
        </View>
)

But it does not print... what am I missing?

1 Answer 1

2

You can just use map to instead.

And use the parameter with a wrap {letter} to render.

Like this:

<View style={styles.app}>
  { ['a', 'b'].map((letter) => 
    <Text>{letter}</Text>
  )}
</View>
Sign up to request clarification or add additional context in comments.

Comments

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.