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?
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>
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.