How can I insert a line break into a <Text> component in React Native?

Curtis picture Curtis · Sep 9, 2015 · Viewed 395.9k times · Source

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.

Answer

Chris Ghenea picture Chris Ghenea · Sep 9, 2015

This should do it:

<Text>
Hi~{"\n"}
this is a test message.
</Text>