Eduardo
Eduardo

Reputation: 1831

React Native: Array of components

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?

Upvotes: 0

Views: 34

Answers (1)

高鵬翔
高鵬翔

Reputation: 2057

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>

Upvotes: 2

Related Questions