My use case:
I’m trying to create a button component, so the children of the component are of ReactNode type, usually string but it could be anything.
Then in my Button component, when I render the children, I wrap them in <Text>
in case they’re a string, but if they’re not if they are for example a bunch of <View>
since they’re nested inside <Text>
, they’ll appear in one line
My question:
If I have for example
<Text>
<View>
<Text>Hello</Text>
</View>
<View>
<Text>There</Text>
</View>
</Text>
How can I have the Hello and There appear on two different lines?
2
Answers
You can use the
{'n'}
newline character between them ?To answer the comment:
Not directly, but with a tricky way, something like this, mapping through the elements wrapped within the button i.e
children
and apply the disred styling to their wrapperView
component, since children can be of different node types so we use theView
as a container and style it :You can have both Text field inside a same View without wrapping them in separate Views like below,
And it will appear in different lines.