I want to insert a new line (like \r\n, <br />) in a Text component in React Native.
If I have:
<text> <br /> Hi~<br /> this is a test message.<br /> </text>
Then React Native renders Hi~ this is a test message.
Is it possible render text to add a new line like so:
Hi~ this is a test message.
To insert a line break into a Text component in React Native, we can add the '\n' character string. to add {'\n'} into the content of Text .
Use the textDecoration property to strikethrough text in React, e.g. <span style={{textDecoration: 'line-through'}}> .
In React, you use the self-closing <br> tag to produce a line break between the text or a section, whereas in HTML you'd use <br> … </br> .
This should do it:
<Text> Hi~{"\n"} this is a test message. </Text>
You can also do:
<Text>{` Hi~ this is a test message. `}</Text>
Easier in my opinion, because you don't have to insert stuff within the string; just wrap it once and it keeps all your line-breaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With